Reputation: 136
I want to search in PHP array , value are fetched from table;
e.g. string is a field in table;
string value are :
1st Value :- Hello my name is harkesh
2nd Value :- Last name is Chauhan
while($data = mysql_fetch_array($query))
{
$array[] = $data['string']
}
now array is pulling the complete string value but now i want to search for particular words in $array[];
e.g
if i type " Last name" it should show me 2nd Value " Last name is Chauhan" and if i type " name" it should show me both the values as both of them contains "name"
How that can be achieved..Thanks
Upvotes: 1
Views: 204
Reputation: 12389
Could use regex with preg_grep() function to search for the values:
print_r(preg_grep('~\bLast name\b~i', $array));
Array ( 1 => 2nd Value :- Last name is Chauhan )
\b
matches a word boundary; Used with i (PCRE_CASELESS)
flag
Test at eval.in; SO Regex FAQ for more regex info
Upvotes: 2