简体   繁体   中英

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.

So here's the code using 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($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.

Check if the result is zero OR false. It's not the same thing. Zero means "I've found it at location zero".

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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