regex search through array?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
tomprogers
Forum Commoner
Posts: 50
Joined: Fri Mar 17, 2006 5:17 pm
Location: Minnesota
Contact:

regex search through array?

Post by tomprogers »

Is there a way to perform a regular expression search through an array without iterating and preg_match()ing?

The php.net doc for array_search says that "needle" can be a string, which sort of implies that it could be something else (which is supported by the "mixed" type next to it in the signature description). I tried using a regex, and it doesn't behave as desired.

Ideally, I'm looking for something like array_search that can take a regex. Otherwise I have to loop, which seems kind of inelegant.

Thanks.
User avatar
superdezign
DevNet Master
Posts: 4135
Joined: Sat Jan 20, 2007 11:06 pm

Post by superdezign »

Technically, array_search() loops as well. There aren't many different ways to traverse an array. ;)
tomprogers
Forum Commoner
Posts: 50
Joined: Fri Mar 17, 2006 5:17 pm
Location: Minnesota
Contact:

Post by tomprogers »

Gah. Okay. Thanks.
Post Reply