Retrieving array values by range of keys

    Date: 10/15/07 (PHP Community)    Keywords: no keywords

    Suppose I have an associative array that looks like this:
    $arr['alpha_1'] = 'some value';
    $arr['alpha_3'] = 'some value';
    $arr['alpha_4'] = 'some value';
    $arr['beta_2'] = 'some value';
    $arr['beta_4'] = 'some value';
    $arr['beta_6'] = 'some value';
    $arr['gamma_1'] = 'some value';
    $arr['gamma_5'] = 'some value';
    $arr['gamma_6'] = 'some value';
    $arr['gamma_7'] = 'some value';


    Let's assume that the array is reasonably large (hundreds of entries).

    Is there an efficient way of getting all the items whose key starts with 'beta'? (without doing a foreach/strncmp loop?)

    Thanks in advance!

    P.S: The array is not sorted.

    Source: http://community.livejournal.com/php/590552.html

« Sessions || 40 Tips for optimizing your... »


antivirus | apache | asp | blogging | browser | bugtracking | cms | crm | css | database | ebay | ecommerce | google | hosting | html | java | jsp | linux | microsoft | mysql | offshore | offshoring | oscommerce | php | postgresql | programming | rss | security | seo | shopping | software | spam | spyware | sql | technology | templates | tracker | virus | web | xml | yahoo | home