したがって、PHPの場合、マルチdim配列でin_arrayを実行するための便利な関数セットがあります。
function in_array_r($needle, $haystack, $strict = false) {
foreach ($haystack as $item) {
if (($strict ? $item === $needle : $item == $needle) || (is_array($item) && in_array_r($needle, $item, $strict))) {
return true;
}
}
return false;
}
しかし、私はjavascriptで同様のものを再作成しようとしましたが、それを機能させることができないようです..これは私が持っているものです:
function in_array_r(needle, haystack) {
var length = haystack.length;
for(var i = 0; i < length; i++) {
if(haystack[i] == needle){
return true;
}
if(typeof haystack[i]=='object'){
if(in_array_r(needle, haystack[i])){
return true;
}
}
}
return false;
}
なぜ機能しないのかわからないので、なぜ機能しないのかを誰かが見つけることができますか?
ありがとう、ジョン