Connecting Tech Pros Worldwide Forums | Help | Site Map

how to search a string in an array

nirmalsingh's Avatar
Familiar Sight
 
Join Date: Sep 2006
Location: Madurai - India
Posts: 217
#1: Apr 10 '07
i just want to verify, is an array value contain a given string or not?
for eg
Expand|Select|Wrap|Line Numbers
  1. <?php
  2. $users="ravi|varman|nirmal|singh|veera|samy|";
  3. $searchword="nirmal";
  4. ?>
  5.  
i wank to return true if $users contain 'nirmal' or false.
without (for loop). i want to know if there is any inbuilt function in php for that?

php php is offline
Newbie
 
Join Date: Apr 2007
Posts: 2
#2: Apr 11 '07

re: how to search a string in an array


try this idea

<?

$users="ravi|varman|nirmal|singh|veera|samy|";
$searchword="nirmal";

$arr=explode('|',$users);
if($arr[2]=='$searchword')
print"yes";
else"no";

?>
Reply