3v4l.org

run code in 300+ PHP versions simultaneously
<?php //{1,22,56,53,34,51,77}这是一个数组,如何不用内部函数和遍历数组的方法判断出 53 在这个数组里。(面试问题) $arr = array(1,22,56,53,34,51,77); function find($item, array $arr, array $currentIndex = array(0)) { $currentIndex = $currentIndex[0]; if (!isset($arr[$currentIndex])) { return false; } if (isset($arr[$currentIndex]) && ($item === $arr[$currentIndex])) { return true; } var_dump($currentIndex); $currentIndex++; $currentIndex = array($currentIndex); return find($item, $arr, $currentIndex); } $exists = find(53, $arr); var_dump($exists);

preferences:
33.28 ms | 402 KiB | 5 Q