【发布时间】:2013-04-22 18:01:32
【问题描述】:
我有 2 个数组:
$arr1 = array('Test', 'Hello', 'World', 'Foo', 'Bar1', 'Bar'); and
$arr2 = array('hello', 'Else', 'World', 'Tes', 'foo', 'BaR1', 'Bar');
我需要比较两个数组并将匹配元素的位置保存到第三个数组$arr3 = (3, 0, 2, 4, 5, 6); //expected result, displaying position of matching element of $arr1 in $arr2.
“匹配”是指所有相同(例如 World)或部分相同(例如 Test 和 Tes)的元素,以及那些相似但大小写不同的元素(例如 Foo 和 foo,酒吧和酒吧)。
我尝试了一系列组合和各种功能,但没有成功,使用了array_intersect(), substr_compare(), array_filter() 等功能。我不是在要求确切的解决方案,只是为了让我走上正确的轨道,因为我整个下午都在绕圈子。
【问题讨论】:
-
您可以使用
strtolower( $str )来匹配大小写。使用正则表达式匹配部分字符串
标签: php arrays string similarity