3v4l.org

run code in 300+ PHP versions simultaneously
<?php $haystack = array( 'A', 'B' => array('BA'), 'C' => array('CA' => array('CAA')), 'D' => array('DA' => array('DAA' => array('DAAA'))) ); function array_find($needle, array $haystack) { $found = false; $search = array('needle' => $needle, 'found' => &$found); array_walk_recursive($haystack, function($val, $key, $found) { if ($found['needle'] == $val) $found['found'] = true; }, $search); return $found;} $find = array('A', 'BA', 'CAA', 'DAAA'); foreach($find as $needle) { if (array_find($needle, $haystack)) { echo $needle, " found".PHP_EOL; } else { echo $needle, " not found".PHP_EOL; } }

preferences:
36.45 ms | 402 KiB | 5 Q