刚刚在我的机器上运行了代码,这将解决问题
$stringA = "1, 2, 3, 4, 5";
$stringB = "1, 2, 4, 5, 6";
$stringA = explode(',', $stringA);
$stringB = explode(',', $stringB);
$Difference_1 = array_diff($stringA, $stringB); // Check string A Against String B
$Difference_2 = array_diff($stringB, $stringA); // Check String B against String A
$Difference = array_merge($Difference_1, $Difference_2); // Merge the two difference arrays together
$Difference = implode(',', $Difference); // Convert to a string
echo "The Difference Between The Two Is: ".$Difference; // Echo the difference
更新
function Differences ($Arg1, $Arg2){
$Arg1 = explode (',', $Arg1);
$Arg2 = explode (',', $Arg2);
$Difference_1 = array_diff($Arg1, $Arg2);
$Difference_2 = array_diff($Arg2, $Arg1);
$Diff = array_merge($Difference_1, $Difference_2);
$Difference = implode(',', $Diff);
return "The Difference Between The Two Is: ".$Difference;
}
$stringA = "1, 2, 3, 4, 5";
$stringB = "1, 2, 4, 5, 6";
// Call By:
echo Differences($stringA, $stringB);
很抱歉延迟更新。我已经习惯了 PHPStorm 作为一个新的脚本编辑器。