Re: Arrays and regex's..
| From: | Andrei Zmievski | Date: | Fri, 23 Jun 2000 20:26:06 +0000 |
| Subject: | Re: Arrays and regex's.. | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-2857@lists.php.net to get a copy of this message | ||
On Fri, 23 Jun 2000, Chad Day wrote:
> I'm completely stumped on something here..
>
> I have an array of strings that I need to be able to select some values out
> of alphabetically. I've sorted the array alphabetically, but am not sure how
> to pull out all the values that start with 'A', or 'B', or whatever letter
> I
> would want. I think a regular expression is needed to check the
> values and dump them into a second array via a loop, but I'm lost on how
> that expression would look.. I'm really new on regex's :( Can anyone assist
> or point me to some good regular expression tutorials?
If you use PHP 4, you're in luck.
$result_array = preg_grep("/^[A-Z]/", $source_array);
-Andrei
Magic 8-ball is much more powerful than we thought. I mean, back in the 70's it
was predicting the nature of software in the 90's -- "Outlook not so good".