note 96198 added to function.in-array

From: Date: Sun, 14 Feb 2010 00:46:12 +0000
Subject: note 96198 added to function.in-array
Groups: php.notes 
Request: Send a blank email to php-notes+get-165940@lists.php.net to get a copy of this message
If you're working with very large 2 dimensional arrays (eg 20,000+ elements) it's much faster to do this... $needle = 'test for this'; $flipped_haystack = array_flip($haystack); if ( isset($flipped_haystack[$needle]) ) { print "Yes it's there!"; } I had a script that went from 30+ seconds down to 2 seconds (when hunting through a 50,000 element array 50,000 times). Remember to only flip it once at the beginning of your code though! ---- Server IP: 69.147.83.197 Probable Submitter: 68.190.213.184 ---- Manual Page -- http://www.php.net/manual/en/function.in-array.php Edit -- https://master.php.net/note/edit/96198 Del: integrated -- https://master.php.net/note/delete/96198/integrated Del: useless -- https://master.php.net/note/delete/96198/useless Del: bad code -- https://master.php.net/note/delete/96198/bad+code Del: spam -- https://master.php.net/note/delete/96198/spam Del: non-english -- https://master.php.net/note/delete/96198/non-english Del: in docs -- https://master.php.net/note/delete/96198/in+docs Del: other reasons-- https://master.php.net/note/delete/96198 Reject -- https://master.php.net/note/reject/96198 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#165940) next »