geting values from arrays in php -


i have following code:

stdclass object ( [orders] => array ( [0] => stdclass object ( [shipping_address] => stdclass object ( [first_name] => john [last_name] => doe [company] => [address_1] => 3927 walnut grove [address_2] => [city] => rosemead [state] => ca [postcode] => 90001 [country] => ) ) [1] => stdclass object ( [shipping_address] => stdclass object ( [first_name] => chris [last_name] => koh [company] => [address_1] => 745 bow [address_2] => [city] => diamond [state] => ca [postcode] => 90015[country] => ) ) ) ) 

how extract first_name both elements?

john , chris

the "array" mishmash of arrays , objects, objects accessed differently.

array values accessed by

$an_array = array('apple','banana'); $an_array[0]; //will return apple 

while object values area accessed by

$an_object->key; 

take @ return object

stdclass object ( //<-- object   [orders] => array ( //<-- array     [0] => stdclass object (  //<-- object       [shipping_address] => stdclass object ( //<-- object         [first_name] => john   etc.. 

so example first name can access with:

$arrayandobjects->orders[0]->shipping_address->first_name 

hope helps understand bit, here links php documentation arrays & objects

http://php.net/manual/en/language.types.object.php http://php.net/manual/en/language.types.array.php


Comments

Popular posts from this blog

java - Could not locate OpenAL library -

c++ - Delete matches in OpenCV (Keypoints and descriptors) -

sorting - opencl Bitonic sort with 64 bits keys -