note 45694 added to function.in-array

From: Date: Wed, 15 Sep 2004 13:16:02 +0000
Subject: note 45694 added to function.in-array
Groups: php.notes 
Request: Send a blank email to php-notes+get-76733@lists.php.net to get a copy of this message
A faster approach than mina86's function for very large arrays Instead of searching the entire array for a value, just use an associative array and use isset(). This way the lookup is in one pass intead of iterating the whole array. //Create associative lookup array while($data){ $lookup_arr[array_pop($data)]++; } //now the quicker search foreach($find_us as $find_me){ if(isset($lookup_arr[$find_me])){ echo "Found $find_me!\n"; } } ---- Manual Page -- http://www.php.net/manual/en/function.in-array.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+45694 Delete -- http://master.php.net/manage/user-notes.php?action=delete+45694&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+45694&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#76733) next »