我有2个字符串
$old_string = "a,b,c,d,";
$ new_string,通过post方法从表单中获取。
$new_string = "c,d,e,f,";
从上面的2个字符串中获取公共子字符串的最佳方法是什么?
$common_string ="a,b,c,d,e,f,";
如何证明c和d已从$ new_string中移除?
非常感谢
答案 0 :(得分:1)
您可以使用explode()
函数将这些函数转换为数组,然后使用union
$old_string = "a,b,c,d,";
$oldArray = explode($old_string, ',');
$new_string = "c,d,e,f,";
$newArray = explode($new_string, ',');
$result = array_unique(array_merge($oldArray, $newArray));
print_r($result); //it is unique and merged
希望这有帮助