我建造了遍歷一個特定的文件夾,並得到一個數組的foreach:腓的foreach in_array保持返回false
foreach ($watchFolder as $key => $value) {
echo '<pre>';
print_r($value);
echo '</pre>';
if((in_array('xml', $watchFolder))) {
echo "true";
} else {
echo "false";
}
foreach ($value as $key => $valueSub) {
$currentWatchPath2 = $currentWatchPath . '\\' . $key;
foreach ($valueSub as $content) {
$currentWatchPath3 = $currentWatchPath2 . '\\' . $content;
}
}
}
如果我打印出來的$watchfolder
我得到這個:
Array (
[test] => Array([videos] => Array()
[xml] => Array())
[test2] => Array([json] => Array([0] => test.json)
[videos] => Array())
)
如果我試試這個:
它返回null
,而它應該返回真的還是?
我現在很困惑,所以我很感激每一個提示和建議。
我想'in_array'只會得到不是鍵的值。 – aldrin27
'in_array'只檢查值,而不檢查關鍵字。 'array_key_exists()'可能會有所幫助。 –
要檢查密鑰,你可以這樣檢查:'isset($ value ['xml'])' –