是的,我知道array_unique
功能,但问题是匹配项在我的搜索词中可能有合法的重复项,例如:
$str = "fruit1: banana, fruit2: orange, fruit3: banana, fruit4: apple, fruit5: banana";
preg_match("@fruit1: (?<fruit1>\w+), fruit2: orange, fruit3: (banana), fruit4: (?<fruit4>apple), fruit5: (banana)@",$str,$match);
array_shift($match); // I dont need whole match
print_r($match);
输出是:
Array
(
[fruit1] => banana
[0] => banana
[1] => banana
[fruit4] => apple
[2] => apple
[3] => banana
)
所以唯一真正重复的键是 [0] 和 [2] 但array_unique
给出:
Array
(
[fruit1] => banana
[fruit4] => apple
)