arrays - PHP - Foreach loop only echoing first letter of string -


i have array looks this:

array(1) {      ["brookybear"]=> array(5) {          ["id"]=> int(20217894)          ["name"]=> string(10) "brookybear"          ["profileiconid"]=> int(603)          ["summonerlevel"]=> int(30)          ["revisiondate"]=> float(1397388011000)      }  } 

when var_dump(); it. i'm trying use foreach loop take "name" value out of it. however, when echo it, "b" output, , not full brookybear.

here foreach loop:

$url="apiurl"; $ch = curl_init(); curl_setopt($ch, curlopt_ssl_verifypeer, false); curl_setopt($ch, curlopt_returntransfer, true); curl_setopt($ch, curlopt_url,$url); $result=curl_exec($ch); $array = json_decode($result, true); foreach($array['brookybear'] $champs) { echo $champs['name']; } 

looks you're looping on 'brookybear' item instead of parent array.

if want see names of $champs:

$array = json_decode($result, true); foreach($array $champs) {     echo $champs['name']; } 

or more clearly:

$champions = json_decode($result, true); foreach($champions $champ) {     echo $champ['name']; } 

Comments

Popular posts from this blog

apache - Remove .php and add trailing slash in url using htaccess not loading css -

javascript - jQuery show full size image on click -