|
Posted by Chung Leong on 05/16/07 22:39
On May 16, 1:01 pm, Taras_96 <taras...@gmail.com> wrote:
> Hi everyone,
>
> I'm wondering if anyone knows whether PHP does some indexing behind
> the scenes to make array searches faster.
>
> What I have is an array of around 100 000 elements, and I have a list
> of 1000 given element which I need to see whether they contained in
> the array. This means 1000 searches on an array of size 100 000. I'm
> hoping that PHP indexes it's keys using a binary tree or
> something.. :)
>
> Thanks
>
> Taras
As others have pointed out, arrays in PHP are hash tables. To search
quickly, you'd want to take advantage of that. For example, if you're
writing a spell-checker, you wouldn't want to store the word list like
this:
array("a", "able", "above", ...)
but rather like this:
array("a" => 1, "able" => 1, "above" => 1);
then check for existence of a word by accessing the array using the
word as the key.
Navigation:
[Reply to this message]
|