php - How to get a value from within an object that is within an array -
i'm trying data out of variable called $items
when var_dump($items); - result this:
array(13) { [0]=> object(stdclass)#868 (2) { ["meta_key"]=> string(17) "email of attendee" ["meta_value"]=> string(68) "some-email@gmail.com" } [2]=> object(stdclass)#804 (2) { ["meta_key"]=> string(28) "name printed on badge:" ["meta_value"]=> string(7) "some name printed" } ...and on 11 more times
i want know if possible email $items code this:
$email = $items find object meta_key has value "email of attendee" return me corresponding value.
what ended doing running $items through foreach loop so:
foreach($items $item){ $items[$item->meta_key]=$item->meta_value; } which converts "meta_keys" values referencing. now:
$email = $items["email of attendee"] echo $email; result some-email@gmail.com posting a. else in similar jam might use each loop converts things
b. more experience can suggest way "email of attendee directly $items, without having run through foreach loop.
this should magic.
foreach($items $item){ // $item holding object here. equals $items[0] in first loop if($item->meta_key == "email of attendee"){ // stuff } }
Comments
Post a Comment