我需要一个帮助。我需要检查字符串是否存在于数组中,并且它应该使用 PHP 进行字母搜索。我在下面解释我的代码。
$resultArr=array("9937229853","9937229856","9937229875");
$searchValue="+919937229853";
在这里,我需要检查一些值 from$searchValue
是否存在于数组中。我正在做如下,但它没有给我正确的结果。
$searchValue="+919937229853";
$resultArr=array("9937229853","9937229856","9937229875");
if(!in_array($searchValue, $resultArr))
{
$flag=1;
}else{
$flag=0;
}
echo $flag;
根据我的要求,这里的结果应该打印,1
因为$searchValue
该数组中也存在一些值,但回显结果即将到来0
。请帮助我。
$searchValue="+919937229853";
$resultArr=array("9937229853","9937229856","9937229875");
foreach($resultArr as $value)
{
if(strpos($value,$searchValue) || strpos($searchValue,$value) || $searchValue==$value)
{
$flag = 1;
break;
}
else
$flag=0;
}
echo $flag;
I think this will do what you are looking for. in_array() method search string in array but for the exact string. strpos can search substring in long string and return the offset number or the index of substring in the long string.
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句