Hi I receive the following error in my homework and I do not know what is the problem hasildata.php on line 21 :
$dataJson = file_get_contents("https://maps.googleapis.com/maps/api/distancematrix/json?units=metric&origins=".$from."&destinations=".$to."&key=%20AIzaSyCWpwVwu1hO6TJW1H8x_zlhrLfbSbQ2r3o");
$data = json_decode($dataJson,true);
$nilaiJarak = $data['rows'][0]['elements'][0]['distance']['text'];
$time=$data['rows'][0]['elements'][0]['duration']['text'];
Screenshot
You must check whether your request is OK or not
$dataJson = file_get_contents("https://maps.googleapis.com/maps/api/distancematrix/json?units=metric&origins=".$from."&destinations=".$to."&key=%20AIzaSyCWpwVwu1hO6TJW1H8x_zlhrLfbSbQ2r3o");
$data = json_decode($dataJson,true);
if ($data['status'] !== "OK") {
// Error
echo $data['error_message'];
// Do something
} else {
$nilaiJarak = $data['rows'][0]['elements'][0]['distance']['text'];
$time=$data['rows'][0]['elements'][0]['duration']['text'];
}
if (($dom[$key]['value'] == 'tr')) {
$dom[$key]['cols'] = 0;
if ($thead) {
$dom[$key]['thead'] = true;
} else {
$dom[$key]['thead'] = false;
++$dom[($dom[$key]['parent'])]['rows'];
array_push($dom[($dom[$key]['parent'])]['trids'], $key);
}
}
these part shows error.
Message: array_push() expects parameter 1 to be array, null given
Filename: tcpdf/tcpdf.php
Line Number: 16937
Magento says Warning: Invalid argument supplied for foreach() on line 4 in my code. Not sure why. Any ideas?
public function itemIsVirtualGift($item){
$product = $item->getProduct();
$_customOptions = $product->getTypeInstance(true)->getOrderOptions($product);
foreach($_customOptions['options'] as $_option){
if (strpos($_option['label'], 'Is this a gift') !== false && strpos($_option['value'], 'Yes') !== false){
return true;
}
}
return false;
}
I have been facing a weird issue that I cant get fixed. Long story short, when I join a minigame on a game that I am creating, it goes fine! But when I exit out of the minigame, it should send me back into the room, but instead it gives me an error.
This is the error:
PHP Catchable fatal error: Argument 1 passed to
Sweater\Server::leaveTable() must be of the type array, string given,
called in /usr/share/nginx/Sweater/Sweater/GameHandler.php on line 208
and defined in /usr/share/nginx/Sweater/Sweater/GameHandler.php on
line 184
I did some research before asking this question and tried the solutions that I came across, but they sadly did not work.
GameHandler.php handleLeaveTable:
function handleLeaveTable(Array $arrData, Client $objClient) {
$intPlayer = $arrData[0];
$this->leaveTable($intPlayer); // Line 208
}
GameHandler.php leaveTable:
function leaveTable(Array $arrData, Client $objClient) { // Line 184
$intPlayer = $arrData[4];
$tableId = $intPlayer->tableId;
if($tableId !== null) {
$seatId = array_search($intPlayer, $this->playersByTableId[$tableId]);
$opponentSeatId = $seatId == 0 ? 1 : 0;
if(isset($this->playersByTableId[$tableId][$opponentSeatId])) {
$this->playersByTableId[$tableId][$opponentSeatId]->addCoins(10);
}
unset($this->playersByTableId[$tableId][$seatId]);
unset($this->tablePopulationById[$tableId][$intPlayer->$strUsername]);
$objClient->sendXt('ut', $objClient->getIntRoom(), $tableId, $seatId);
$intPlayer->tableId = null;
if(count($this->playersByTableId[$tableId]) == 0) {
$this->playersByTableId[$tableId] = array();
$this->gamesByTableId[$tableId] = null;
}
}
}
What is the issue here? I have checked everything and could not come to a solution.
Edit, What $arrData is:
function decodeData($strData){
$arrData = simplexml_load_string($strData, 'SimpleXMLElement', LIBXML_NOCDATA);
if($arrData === false){
throw new Exceptions\HandlingException('Unable to parse client\'s XML data');
}
$arrData = json_decode(json_encode((array)$arrData), true);
return $arrData;
}
function handleData($strData, $objClient){
$arrData = explode($this->arrConfig['Packets']['Delimiter'], $strData);
array_pop($arrData);
foreach($arrData as $strData){
Silk\Logger::Log('Received data: ' . $strData);
$strSubstring = substr($strData, 0, 1);
$blnPossibleXML = $strSubstring == '<' ? true : false;
$blnPossibleGame = $strSubstring == '%' ? true : false;
if($blnPossibleXML === false && $blnPossibleGame === false){
throw new Exceptions\HandlingException('Bad client detected!');
}
$blnPossibleXML ?
$this->handleXMLData($strData, $objClient):
$this->handleGameData($strData, $objClient);
}
unset($arrData);
}
PHP Catchable fatal error: Argument 1 passed to
Sweater\Server::leaveTable() must be of the type array, string given,
called in /usr/share/nginx/Sweater/Sweater/GameHandler.php on line 208
and defined in /usr/share/nginx/Sweater/Sweater/GameHandler.php on
line 184
From $arrData you take the first element which is string
$intPlayer = $arrData[0];
$this->leaveTable($intPlayer); // Line 208
In GameHandler.php handleLeaveTable:
You take the first element form an array
And then in GameHandler.php leaveTable:
You are trying to access that element as an array and then take the 5th element
I'm getting the following error
PHP Notice: Undefined offset: 4 -- LINE 190
in the chunk of code below. I've tried a couple different solutions that I found here including isset, but nothing seems to work.
Does anyone have any suggestions?
// If we don't have any data get it from the db
$GLOBALS['AKB_CLASS_HELPER']->getCatsInfo();
$parentid = 0;
if (!empty($arrCats[0])) {
foreach ($arrCats as $cat) {
foreach ($GLOBALS['AKB_CLASS_HELPER']->tree->nodesByPid[$parentid] as $catid) { <--------- LINE190
$pcat = $GLOBALS['AKB_CLASS_HELPER']->catsById[$catid];
if (strtolower($pcat['name']) == strtolower($cat)) {
$GLOBALS['CatTrails'][] = array ($pcat['categoryid'], $cat);
$this->_catId = $pcat['categoryid'];
$parentid = $pcat['categoryid'];
break;
}
}
}
}