php - How to get object(stdClass) from array without the key? -


i looked @ how object(stdclass) array, answer didn't me much.

here small example:

array (     [25] => stdclass object         (             [id] => 25             [name] => foo         )      [27] => stdclass object         (             [id] => 27             [name] => bar         ) ) 

note position same id, i'm unable know exacly position, can't call

// since idk how many $items = array_shift(array_values($array)); $items->name; 

nor

// since idk position $items = array_shift(array_values($array[0])); $items->name; 

the solution find using foreach

foreach($array $item){     echo '<pre>';     print_r($item->name);     echo '</pre>'; } 

but last resource, because have 3 sub-arrays, not $array $array['foo'] && $array['bar'] && $array['foobar'] , inside each structure above. besides that, need test if content exists, using if(count($array['foo']) > 0.

not sure, i'm guessing want know keys (positions say) of array are. use array_keys that:

$keys = array_keys($array);  // $keys array(25, 27) 

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? -