JSON Parsing issue with PHP -


i'm attempting pull in data wowprogress api. want parse data online , decode them directly while posting them view. i'm still learning, seem having issues array. need help.

$json = file_get_contents("http://www.wowprogress.com/guild/eu/twisting-nether/hellenic%20horde/json_rank"); if($json == false) { throw new exception("failed load infomation. check setup options"); } $result = json_decode($json, true); echo "<pre>"; foreach ($result["realm_rank"] $value) {     print_r($value); } echo "</pre>"; 

but receive "invalid argument supplied foreach()"

would love help. in advance!

sorry english. english not native language.

the $result['realm_rank'] string, not array.

therefore, foreach on causing error.

this error causes when either array not set, or blank or not array.

<?php $json = file_get_contents("http://www.wowprogress.com/guild/eu/twisting-nether/hellenic%20horde/json_rank"); if ($json == false) {  throw new exception("failed load infomation. check setup options"); } $result = json_decode($json, true);  if (isset($result['realm_rank'])) {   if (is_array($result['realm_rank'])) {    foreach ($result["realm_rank"] $value) {     echo "<pre>";     print_r($value);     echo "</pre>";    }   }    else {    echo $result['realm_rank'];   }  } else {  echo 'unknown error'; } ?> 

Comments

Popular posts from this blog

Hatching array of circles in AutoCAD using c# -

ios - UITEXTFIELD InputView Uipicker not working in swift -

Python Pig Latin Translator -