/** 模糊搜索数组 $data 数组 $key 匹配字符串 $info 字段 **/ function arrlikes($data,$key,$info){ $arr = array(); foreach($data as $k=>$v ){ if (strstr( $v[$info] , $key ) !== false ){ array_push($arr, $v); } } return $arr; } //支持多个值 $arr = array(0 => 'abc', 1 => 'def', 2 => 'ghijk', 3 => 'lmnxyz',4 => 'lmndsdsdssdsdsxyz'); $results = array(); foreach ($arr as $value) { if (strpos($value, 'xyz') !== false) { $results[] = $value; } } if( empty($results) ) { echo 'No matches found.'; }else{ echo "'xyz' was found in: ".implode('; ', $results); }
php数组中的某个字段的值进行模糊搜索
阅读:2861 输入:2021-12-13 21:35:27