Stack Exchange
Find the value for a selected key in an array
I need to find the price for the key sub_section_html.
Example: Where [sub_section_html] => waistbandImage echo [price]
I get the key with array_search but how do I get the price value that corresponds to that entry?
stdClass Object ( [data_id] => 65 [name_short_en] => white [price] => 720 [sub_section] => 1 [sub_section_html] => bodyImage ) 
stdClass Object ( [data_id] => 88 [name_short_en] => brown [price] => 80 [sub_section] => 2 [sub_section_html] => waistbandImage ) 
stdClass Object ( [data_id] => 101 [name_short_en] => white [price] => 70 [sub_section] => 3 [sub_section_html] => collarImage ) 
stdClass Object ( [data_id] => 262 [name_short_en] => Lace/blue/white [price] => 330 [sub_section] => 8 [sub_section_html] => leftsleeveImage ) 


So you have the key and cannot retrieve the data using that key? Do you know how to work with arrays in php?

I think you can do find that price using foreach Check http://pastie.org/4106538

this is an object not array... you should write
echo $object_name->key;

If this is what you're working with, then I'd strongly suggest you switch to proper arrays. This is basically abuse of the stdClass object (which you'd normally never instantiate).  Using stdClass in place of arrays has no benefits and considerable drawbacks. http://stackoverflow.com/questions/2022544/can-i-use-stdclass-like-an-array http://stackoverflow.com/questions/1869812/casting-an-array-with-numeric-keys-as-an-object

And if you dont want to change your code and still want to get the result, you can convert object to array like $array = (array) $your_object; and than you can search for key and get the price value from converted array.
