note 72914 deleted from function.array-search by danbrown

From: Date: Wed, 29 Apr 2009 12:58:33 +0000
Subject: note 72914 deleted from function.array-search by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-153980@lists.php.net to get a copy of this message
Note Submitter: php dot net at surfnation dot de ---- Here is my solution for a 2-dimensional search. It combines the foreach with the faster array_search (I did use a recursive way, cause I am at war with it :) ). it is quick, easy and (hopefully) very stable. <?php $map = array(); $map[1][1] = 11; $map[2][1] = 21; $map[3][1] = 31; $map[1][3] = 13; $varGesuchtesElement = 21; $varGefundenesElement = fktMultiArraySearch($map,$varGesuchtesElement); if ($varGefundenesElement){ print_r($varGefundenesElement); } else{ echo "Kein Element gefunden!"; } function fktMultiArraySearch($arrInArray,$varSearchValue){ foreach ($arrInArray as $key => $row){ $ergebnis = array_search($varSearchValue, $row); if ($ergebnis){ $arrReturnValue[0] = $key; $arrReturnValue[1] = $ergebnis; return $arrReturnValue; } } } ?>

« previous php.notes (#153980) next »