note 57762 added to function.in-array
| From: | evildictaitor at hotmail dot com | Date: | Thu, 13 Oct 2005 15:06:56 +0000 |
| Subject: | note 57762 added to function.in-array | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-96964@lists.php.net to get a copy of this message | ||
To look through a large array, it is much more efficient when it is sorted to use a binary chop
method, so that the number of calls is equal to log(number_of_values_in_array) / log2 rather than
equal to the number of values in the array.
For a million values in an array, it can therefore return whether this index exists in a file using
no more than 20 calls to the array rather than a million. This makes it 50,000 times more efficient
for an array of this size. I'm sure you can imagine what a million calls can do to a processor,
and it isn't nice.
Hope this helps someone.
----
Manual Page -- http://www.php.net/manual/en/function.in-array.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+57762
Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+57762&report=yes&reason=added+to+the+manual
Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+57762&report=yes&reason=bad+code
Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+57762&report=yes&reason=spam
Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+57762&report=yes&reason=useless
Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+57762&report=yes&reason=non-english
Delete: already in docs -- http://master.php.net/manage/user-notes.php?action=delete+57762&report=yes&reason=already+in+docs
Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+57762&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+57762&report=yes
Search -- http://master.php.net/manage/user-notes.php