You are here: Re: Retrieving array values by range of keys « PHP Programming Language « IT news, forums, messages
Re: Retrieving array values by range of keys

Posted by Captain Paralytic on 10/15/07 13:45

On 15 Oct, 14:37, "Sanders Kaufman" <bu...@kaufman.net> wrote:
> "Captain Paralytic" <paul_laut...@yahoo.com> wrote in message
>
> news:1192454252.346643.76180@i13g2000prf.googlegroups.com...
>
>
>
>
>
> > On 15 Oct, 14:09, WildernessCat <wilderness...@gmail.com> wrote:
> >> Hello there!
>
> >> 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,
> >> Danny
>
> > Something like:
>
> > preg_grep('/^beta/',array_keys($arr));
>
> > should give you all the keys that start with 'beta'
>
> What does the return value look like - array? string?- Hide quoted text -
>
> - Show quoted text -

Why ask me when you can just go to:
http://uk3.php.net/manual/en/function.preg-grep.php
and read it there?

Note that this won't solve the OP's whole problem as he wants the
values rather than the keys, but it's a start.

 

Navigation:

[Reply to this 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

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