PHP实现模糊查询
2017-09-08 本文已影响0人
Fbetter
$a是一个数组
if (strlen($q) > 0)
{
$hint="";
for($i=0; $i<count($a); $i++)
{
//strtolower将所有字母转换为小写
//substr返回指定长度字符串
if (strtolower($q)==strtolower(substr($a[$i],0,strlen($q))))
{
if ($hint=="")
{
$hint=$a[$i];
}
else
{
$hint=$hint." , ".$a[$i];
}
}
}
}