[英]PHP comparing strings from two separate arrays using stripos
所以我有两个数组,我需要遍历和比较字符串。 我的问题是执行此操作的最佳方法是什么,因为当我使用stripos()
它会失败(未找到匹配项),但是仅使用if($a1 == $a2){}
正常工作。
所以这是使用stripos()
的代码:
foreach(array_combine($import_data['item_id'], $import_data['title']) as $item_id => $title) {
foreach($unlinked as $product) {
if(stripos($title, $product['title'] !== false)) {
echo $product['title'] . '<br>';
echo $item_id . ' - ' . $product['product_id'] . '<br>';
}
}
}
但是将if语句更改为
if($product['title'] == $title) {}
然后工作正常。 因此,使用这种方法比较字符串是否可以,还是有比较准确的方法比较PHP中的字符串?
检查结果是否为零或错误。 不一样 零表示“我在零位置找到了它”。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.