Reply to Re: how are php arrays indexed?

Your name:

Reply:


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.

[Back to original message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация