比較元素我有2個數組:PHP - 如何部分在2個陣列
$arr1 = array('Test', 'Hello', 'World', 'Foo', 'Bar1', 'Bar'); and
$arr2 = array('hello', 'Else', 'World', 'Tes', 'foo', 'BaR1', 'Bar');
我需要比較2個陣列和匹配元件的位置保存到第三陣列$arr3 = (3, 0, 2, 4, 5, 6); //expected result, displaying position of matching element of $arr1 in $arr2.
「匹配」是指所有相同(例如世界)或部分相同的元素(例如測試& Tes)以及那些相似但具有不同情況的元素(例如Foo & foo,Bar & bar )。
我試過了一系列的組合和各種功能沒有成功,使用像array_intersect(), substr_compare(), array_filter()
等功能。我沒有要求確切的解決方案,只是爲了讓我走上正確的軌道,因爲我整個下午都在圈子裏走動。
你可以用'用strtolower($ STR)'匹配小寫和大寫。使用正則表達式來匹配部分字符串 – 2013-04-22 18:08:12