note 77863 deleted from function.array-search by bjori

From: Date: Mon, 17 Sep 2007 12:58:10 +0000
Subject: note 77863 deleted from function.array-search by bjori
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-130552@lists.php.net to get a copy of this message
Note Submitter: logicearth at gmail dot com Reason: useless ---- There is probably a much more efficient way to do this, handle an unlimited depth but while supporting single declensions arrays. <?php function array_search_recursive ($needle, $haystack, $strict = false, $depth = 0) { $tmp = array_search($needle, $haystack, $strict); if ($tmp !== false) { return array($depth => $tmp); } foreach ($haystack as $key => $value) { if (is_array($value)) { $tmp = array_search_recursive($needle, $value, $strict, ++$depth); if ($tmp !== false) { return array_merge(array($depth =>$key), $tmp); } } } return false; } $a = array( 'image/gif' => 'gif', 'image/jpeg' => array('jpg', 'jpeg', 'jpe', 'more' => array('n', 'm', 'x', 'find me')), 'image/png' => 'png' ); var_dump(array_search_recursive('find me', $a)); ?>

« previous php.notes (#130552) next »