Create array from objects php -


i have json result file decoded array of objects. using foreach find correct player , wish create array information under correct player.

this snippet of array of objects:

object(stdclass)#3 (1) {   ["result"]=>   object(stdclass)#4 (18) {     ["players"]=>     array(10) {       [0]=>       object(stdclass)#5 (24) {         ["account_id"]=>         int(72775718)         ["player_slot"]=>         int(0)         ["hero_id"]=>         int(46)         ["item_0"]=>         int(50)         ["item_1"]=>         int(139)         ["item_2"]=>         int(149)         ["item_3"]=>         int(147)         ["item_4"]=>         int(168)         ["item_5"]=>         int(116)         ["kills"]=>         int(26)         ["deaths"]=>         int(10)         ["assists"]=>         int(9)         ["leaver_status"]=>         int(0)         ["gold"]=>         int(1622)         ["last_hits"]=>         int(285) 

there several players in this, , using account_id find correct player with:

foreach ($data_decoded->result->players $val){             if($val->account_id == $this->playerid){                 echo "found you!"."\n"; } 

how create array of subsequent results? example, underneath account_id, store of information (player_slot, hero_id, etc.) need use foreach? if don't know how word it.

i have tried:

    foreach ($data_decoded->result->players $val){         if($val->account_id == $this->playerid){             echo "found you!"."\n";              foreach($val $test){                 $dataarray=array($test);              } 

but adds values on same "level" (poor terminology) $val, , not subsequent values?

if want change array can simply cast it:

if ($val->account_id == $this->playerid) {     $dataarray = (array) $val; } 

demo: https://eval.in/116967


Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -