Search for a string or part of string in PHP

后端 未结 7 1686
春和景丽
春和景丽 2020-12-06 16:14

I am doing a very small online store application in PHP. So I have an array of maps in PHP. I want to search for a string (a product) in the array. I looked at array_search

7条回答
  •  孤街浪徒
    2020-12-06 17:08

    foreach($array as $item){
      if(strpos($item,"mysearchword")!== false){
        echo 'found';
      }
    }
    

    or you can use preg_match for more flexible search instead of strpos.

提交回复
热议问题