Re: searching an array for words starting with 'p'
| From: | Tech Support | Date: | Tue, 30 Jul 2002 17:55:27 +0000 |
| Subject: | Re: searching an array for words starting with 'p' | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-110384@lists.php.net to get a copy of this message | ||
try preg_grep()
http://www.php.net/manual/en/function.preg-grep.php
example:
<?
$word = array('alpha', 'beta', 'php');
// match anything beginning with upper or lower case p
$matches_array = preg_grep('/^(p|P).*/', $word);
print_r($matches_array);
?>
Jim Grill
Support
Web-1 Hosting
http://www.web-1hosting.net
----- Original Message -----
From: "andy" <news.letters@gmx.de>
To: <php-general@lists.php.net>
Sent: Tuesday, July 30, 2002 10:36 AM
Subject: [PHP] searching an array for words starting with 'p'
> Hi there,
>
> I am wondering how to search an array for words starting with a certain
> character.
>
> E.G:
>
> $word = array('alpha', 'beta', 'php');
>
> I would like to check if there is a word in the array starting with p
>
> Is there alrready a function for this?
>
> Thanx, Andy
>
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
>