Hi! I want to search string having value like "CMS" in array $row, below code is searching for exact "CMS".
if (mysql_num_rows($sql_result)>0)
{
while ($row = mysql_fetch_assoc($sql_result))
{ $counter++;
if (in_array("CMS", $row))
{ $cms++; }
}
}
I'll be grateful if any one can guide me to how to search string for value LIKE "CMS" in array $row.
Use strpos and serialize
if (mysql_num_rows($sql_result)>0)
{
while ($row = mysql_fetch_assoc($sql_result))
{ $counter++;
if (strpos(serialize($row),"CMS")!==false) //<--- Changed this `if` statement, nothing else
{ $cms++; }
}
}
You could serialize your array and then do a strpos to check whether the needle is inside the array or not. This is something similar like doing a LIKE as you requested.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With