[英]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.