php selecting hash using wildcards

Posted by tipu on Stack Overflow See other posts from Stack Overflow or by tipu
Published on 2010-04-09T02:09:56Z Indexed on 2010/04/09 2:13 UTC
Read the original article Hit count: 452

Filed under:
|
|

Say I have a hashmap,

$hash = array('fox' => 'some value',
              'fort' => 'some value 2',
              'fork' => 'some value again);

I am trying to accomplish an autocomplete feature. When the user types 'fo', I would like to retrieve, via ajax, the 3 keys from $hash. When the user types 'for', I would like to only retrieve the keys fort and fork. Is this possible?

What I was thinking was using binary search to isolate the keys with 'f', instead of brute-force searching. Then continue eliminating the indexes as the user types out their query. Is there a more efficient solution to this?

© Stack Overflow or respective owner

Related posts about php

Related posts about hashmap