how to search a string in an array

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • nirmalsingh
    New Member
    • Sep 2006
    • 218

    how to search a string in an array

    i just want to verify, is an array value contain a given string or not?
    for eg
    Code:
    <?php
    $users="ravi|varman|nirmal|singh|veera|samy|";
    $searchword="nirmal";
    ?>
    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
    New Member
    • Apr 2007
    • 2

    #2
    try this idea

    <?

    $users="ravi|va rman|nirmal|sin gh|veera|samy|" ;
    $searchword="ni rmal";

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

    ?>

    Comment

    Working...