note 92460 added to function.in-array

From: Date: Sat, 25 Jul 2009 07:38:16 +0000
Subject: note 92460 added to function.in-array
Groups: php.notes 
Request: Send a blank email to php-notes+get-158714@lists.php.net to get a copy of this message
This function is five times faster than in_array(). It uses a binary search and should be able to be used as a direct replacement: function fast_in_array($elem, $array) { $top = sizeof($array) -1; $bot = 0; while($top >= $bot) { $p = floor(($top + $bot) / 2); if ($array[$p] < $elem) $bot = $p + 1; elseif ($array[$p] > $elem) $top = $p - 1; else return TRUE; } return FALSE; } ---- Server IP: 64.71.164.2 Probable Submitter: 86.156.50.238 ---- Manual Page -- http://www.php.net/manual/en/function.in-array.php Edit -- https://master.php.net/note/edit/92460 Del: integrated -- https://master.php.net/note/delete/92460/integrated Del: useless -- https://master.php.net/note/delete/92460/useless Del: bad code -- https://master.php.net/note/delete/92460/bad+code Del: spam -- https://master.php.net/note/delete/92460/spam Del: non-english -- https://master.php.net/note/delete/92460/non-english Del: in docs -- https://master.php.net/note/delete/92460/in+docs Del: other reasons-- https://master.php.net/note/delete/92460 Reject -- https://master.php.net/note/reject/92460 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#158714) next »