简体   繁体   English

PHP使用Stripos比较来自两个单独数组的字符串

[英]PHP comparing strings from two separate arrays using stripos

So I have two arrays that i need to loop through and compare strings. 所以我有两个数组,我需要遍历和比较字符串。 My question is what would be the best way to do this because when I use stripos() it fails (no matches found) but just using if($a1 == $a2){} it works fine. 我的问题是执行此操作的最佳方法是什么,因为当我使用stripos()它会失败(未找到匹配项),但是仅使用if($a1 == $a2){}正常工作。

So here's the code using stripos() : 所以这是使用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>';
    }
  }
}

But changing the if statement to 但是将if语句更改为

if($product['title'] == $title) {}

It then works fine. 然后工作正常。 So, is it OK to compare strings using this method or is there a more accurate way of comparing strings in PHP. 因此,使用这种方法比较字符串是否可以,还是有比较准确的方法比较PHP中的字符串?

Check if the result is zero OR false. 检查结果是否为零或错误。 It's not the same thing. 不一样 Zero means "I've found it at location zero". 零表示“我在零位置找到了它”。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM