Page 2 of 2

Posted: Thu Aug 03, 2006 7:24 pm
by Ollie Saunders
Ex.

Code: Select all

$keys = array("apples", "oranges", "mangoes", "tomatoes", "pickles");
if (in_array('mangoes', $keys)) { ... }
vs

Code: Select all

$keys = array("apples" => 1, "oranges" => 1, "mangoes" => 1, "tomatoes" => 1, "pickles" => 1);
if (isset($keys['mangoes'])) { ... }
The bottom search mechanism is roughly 3 times faster.
I knew there was a difference, but 3 times! whoa!

Posted: Thu Aug 03, 2006 8:05 pm
by feyd
Likely it benefits from hash tables.