Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/string/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
比较两个字符串并在php中返回不同的值_Php_String - Fatal编程技术网

比较两个字符串并在php中返回不同的值

比较两个字符串并在php中返回不同的值,php,string,Php,String,当比较$a和$b时,它将返回一个数组$arr={goes,comes}来自与$a不同的$b。请建议一个解决方案尝试使用PHP函数 $a = "what go around, come around"; $b = "what goes around, comes around"; 它将array1与一个或多个其他数组进行比较,并返回array1中不存在于任何其他数组中的值。只需使用preg_split和array_diff,如 输出: 你想完成什么?$arr=array\u diffstr\u

当比较$a和$b时,它将返回一个数组$arr={goes,comes}来自与$a不同的$b。请建议一个解决方案

尝试使用PHP函数

$a = "what go around, come around";
$b = "what goes around, comes around";
它将array1与一个或多个其他数组进行比较,并返回array1中不存在于任何其他数组中的值。

只需使用preg_split和array_diff,如

输出:


你想完成什么?$arr=array\u diffstr\u word\u count$b,2,str\u word\u count$a,2;可能重复@MarkBaker这是一个很好的答案,请将其作为答案发布+1.
array array_diff ( array $array1 , array $array2 [, array $... ] )
$a = "what go around, come around";
$b = "what goes around, comes around";
echo implode(',',array_diff(preg_split('/\h/',$b),preg_split('/\h/',$a)));
goes,comes