一個數組中有多個值,如今須要輸入某個字符串,要模糊查詢出全部帶有這個字符串的數組中的值,該如何實現呢?看例子:數組
$keywords = 'dd';
$arrays = array(
'0' => 'db_aabbccddee',
'1' => 'aabbccdd',
'2' => 'aaa',
'3' => 'aabb',
'4' => 'aabbcc',
'5' => 'aabbccddeeff'
);.net
$arr = array();
foreach($arrays as $key=>$values ){
if (strstr( $values , $keywords ) !== false ){
array_push($arr, $values);
}
}blog
echo '<pre>';print_r($arr);字符串
//能夠看到輸出的結果爲:foreach
Array ( [0] => db_aabbccddee [1] => aabbccdd [2] => aabbccddeeff )
這樣,就實現了數組的模糊查詢。專欄
來源,宇智波鼬的專欄 http://blog.csdn.net/qq_22327455qq