note 72914 added to function.array-search

From: Date: Sat, 03 Feb 2007 23:03:51 +0000
Subject: note 72914 added to function.array-search
Groups: php.notes 
Request: Send a blank email to php-notes+get-122777@lists.php.net to get a copy of this message
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; } } } ?> ---- Server IP: 69.147.83.197 Probable Submitter: 87.160.218.131 ---- Manual Page -- http://www.php.net/manual/en/function.array-search.php Edit -- https://master.php.net/note/edit/72914 Del: integrated -- https://master.php.net/note/delete/72914/integrated Del: useless -- https://master.php.net/note/delete/72914/useless Del: bad code -- https://master.php.net/note/delete/72914/bad+code Del: spam -- https://master.php.net/note/delete/72914/spam Del: non-english -- https://master.php.net/note/delete/72914/non-english Del: in docs -- https://master.php.net/note/delete/72914/in+docs Del: other reasons-- https://master.php.net/note/delete/72914 Reject -- https://master.php.net/note/reject/72914 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#122777) next »