php: easy way to compare array

Joined
12 Feb 2006
Posts
17,643
Location
Surrey
is there a better way to compare a string against an array other then using foreach...? always felt that although relatively simple this could still be done a lot easier but have never come across another way.
 
is there a better way to compare a string against an array other then using foreach...? always felt that although relatively simple this could still be done a lot easier but have never come across another way.

EDIT for some reason I read PHP but my brain thought perl! lol
PHP:
if(grep {/$string/} @array){
print "OMFG String found\n";
} else{
print "Seriously no way! string not found\n";
}

Looks like PHP has something similar though, never used PHP so wouldn't listen to me though!
PHP:
if(preg_grep("/string/",$array){
}
[/PHP]
 
Last edited:
is there a better way to compare a string against an array other then using foreach...? always felt that although relatively simple this could still be done a lot easier but have never come across another way.

What exactly are you trying to do? See what items are in one but not the other?
 
Back
Top Bottom