How do I check that an array key equals a value with an array like this:
Array ( [0] => stdClass Object ( [subCategory] => All Headphones [description] => [image] => ) [1] => stdClass Object ( [subCategory] => Behind-the-Neck Headphones [description] => [image] => ) [2] => stdClass Object ( [subCategory] => Clip-On Headphones [description] => [image] => ) [3] => stdClass Object ( [subCategory] => Earbud Headphones [description] => [image] => ) [4] => stdClass Object ( [subCategory] => Kids' Headphones [description] => [image] => ) )
I’ve tried using this code:
if(array_key_exists('subCategory',$array) {
echo "Exists";
}
That wont work because you have an array of standard objects… the only array keys even present are integers. So the question is what are you trying to detect? If you want to check the if an object has the
subCategoryproperty you can doisset($obj->subCategory). If you want to ensure that each object in your array has that property then you need to loop:I dont think thats what you really want to do though, some more info would be helpful.