有一天我問了一個與此相關的問題,我得到了一個答案,但它沒有做我想要的。下面是遍歷多維關聯數組,檢查按鍵是否是數組中(從回答我剛纔的問題)的方法,我有:查找嵌套關聯數組中的鍵
private function checkKeyIsInArray($dataItemName, $array)
{
foreach ($array as $key => $value)
{
// convert $key to string to prevent key type convertion
echo '<pre>The key: '.(string) $key.'</pre>';
if ((string)$key == $dataItemName)
return true;
if (is_array($value))
return $this->checkKeyIsInArray($dataItemName, $value);
}
return false;
}
這裏是我的陣列stucture:
Array (
[0] => Array ([reset_time] => 2013-12-11 22:24:25)
[1] => Array ([email] => [email protected])
)
該方法遍歷第一個數組分支,但不是第二個。有人可以解釋爲什麼這可能是這種情況嗎?看來我失去了一些東西。
你能展示把你的問題的輸出? –
您的多維數組的示例... – Prix
爲什麼不使用內置PHP函數的array_key_exists? – user602525