( ! ) Warning: Invalid argument supplied for foreach() in C:\wamp\apps\wg\index.php on line 22 Call Stack # Time Memory Function Location 1 0.0010 259696 {main}( ) ..\index.php:0 ( ! ) Notice: Undefined variable: id in C:\wamp\apps\wg\index.php on line 31 Call Stack # Time Memory Function Location 1 0.0010 259696 {main}( ) ..\index.php:0 ( ! ) Warning: Invalid argument supplied for foreach() in C:\wamp\apps\wg\index.php on line 34 Call Stack # Time Memory Function Location 1 0.0010 259696 {main}( ) ..\index.php:0 ( ! ) Notice: Undefined variable: clan in C:\wamp\apps\wg\index.php on line 55 Call Stack # Time Memory Function Location 1 0.0010 259696 {main}( ) ..\index.php:0 ( ! ) Warning: Invalid argument supplied for foreach() in C:\wamp\apps\wg\index.php on line 58 Call Stack # Time Memory Function Location 1 0.0010 259696 {main}( ) ..\index.php:0this code does not work
<?php //Идентификатор приложения (Application_id), регистрация приложения [ru.wargaming.net] $appid = "42f70f94f175efd8c5a9a6075afaee88"; //Тело скрипта if(isset($_POST['nick'])) { $nick = $_POST['nick']; //Получение account_id (метод account/list) $urlID = "[api.worldoftanks.ru];; $curl = curl_init(); curl_setopt($curl, CURLOPT_URL, $urlID); curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); $resultID = json_decode(curl_exec($curl), true); foreach($resultID['data'] as $key => $value) { /* Определяем account_id Значение всех параметров можно изучить в документации к методу account/list [ru.wargaming.net] */ $id = $value['account_id']; } //Получение общей статистики по боям (метод account/info) $urlStat = "[api.worldoftanks.ru];; curl_setopt($curl, CURLOPT_URL, $urlStat); $resultStat = json_decode(curl_exec($curl), true); foreach($resultStat['data'] as $key => $valueInfo){ /* Определяем общее количество побед Значение всех параметров можно изучить в документации к методу account/info [ru.wargaming.net] */ $wins = $valueInfo['statistics']['all']['wins']; curl_close($curl); echo "<b>AccountID:</b> $id <br /> <b>Wins:</b> $wins"; } } ?> <p><form method="post">Nick <input name="nick" type="text"><input type="submit" value="Check!"></form></p>
foreach($resultID['data'] as $key => $value) {insert
error_log(print_r($resultID['data'],true)) ;Then see in wamp/logs/php_error.log what is the content of the variable.
foreach($resultID['data'] as $key => $value) {insert
error_log(print_r($resultID,true)) ;Then see in wamp/logs/php_error.log what is the content of the array $resultID and find that $resultID ['data'] is not an array.
<?php //Идентификатор приложения (Application_id), регистрация приложения [ru.wargaming.net] $appid = "demo"; //Тело скрипта if(isset($_POST['nick'])) { $nick = $_POST['nick']; //Получение account_id (метод account/list) $urlID = "[api.worldoftanks.ru];; $curl = curl_init(); curl_setopt($curl, CURLOPT_URL, $urlID); curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); $resultID = json_decode(curl_exec($curl), true); foreach($resultID['data'] as $key => $value) { error_log(print_r($resultID,true)) ; /* Определяем account_id Значение всех параметров можно изучить в документации к методу account/list [ru.wargaming.net] */ $id = $value['account_id']; } //Получение общей статистики по боям (метод account/info) $urlStat = "[api.worldoftanks.ru];; curl_setopt($curl, CURLOPT_URL, $urlStat); $resultStat = json_decode(curl_exec($curl), true); foreach($resultStat['data'] as $key => $valueInfo){ /* Определяем общее количество побед Значение всех параметров можно изучить в документации к методу account/info [ru.wargaming.net] */ $wins = $valueInfo['statistics']['all']['wins']; curl_close($curl); echo "<b>AccountID:</b> $id <br /> <b>Wins:</b> $wins"; } } ?> <p><form method="post">Nick <input name="nick" type="text"><input type="submit" value="Check!"></form></p>
[01-Mar-2015 10:38:41 Europe/Paris] PHP Warning: Invalid argument supplied for foreach() in C:\wamp\apps\wg\index.php on line 14 [01-Mar-2015 10:38:41 Europe/Paris] PHP Stack trace: [01-Mar-2015 10:38:41 Europe/Paris] PHP 1. {main}() C:\wamp\apps\wg\index.php:0 [01-Mar-2015 10:38:41 Europe/Paris] PHP Notice: Undefined variable: id in C:\wamp\apps\wg\index.php on line 24 [01-Mar-2015 10:38:41 Europe/Paris] PHP Stack trace: [01-Mar-2015 10:38:41 Europe/Paris] PHP 1. {main}() C:\wamp\apps\wg\index.php:0 [01-Mar-2015 10:38:41 Europe/Paris] PHP Warning: Invalid argument supplied for foreach() in C:\wamp\apps\wg\index.php on line 27 [01-Mar-2015 10:38:41 Europe/Paris] PHP Stack trace: [01-Mar-2015 10:38:41 Europe/Paris] PHP 1. {main}() C:\wamp\apps\wg\index.php:0
foreach($resultID['data'] as $key => $value) { error_log(print_r($resultID,true)) ;it is not good. I wrote before... insert
error_log(print_r($resultID,true)) ; foreach($resultID['data'] as $key => $value) {In order to obtain the contents of the array $resultID before the error is generated.