我如何檢查數組鍵等於值有一個這樣的數組:PHP如何檢查數組鍵是否等於某個值?
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] =>))
我已經使用這個代碼的嘗試:
if(array_key_exists('subCategory',$array) {
echo "Exists";
}
您試圖訪問的內容不是數組鍵,而是對象屬性。所以首先告訴我們你真正想要達到的目標? – redmoon7777 2012-01-05 04:17:59