2015-10-07 26 views
-3
$a = "what go around, come around"; 
$b = "what goes around, comes around"; 

返回不同的值進行比較$a$b時,它將從$b即從$a不同返回數組$arr = {"goes","comes"}。請建議一個解決方案比較兩個串和在PHP

+1

[?你嘗試過什麼(http://mattgemmell.com/你試過什麼/) – Epodax

+0

你想完成什麼? –

+1

'$ arr = array_diff(str_word_count($ b,2),str_word_count($ a,2));' –

回答

0

只需使用preg_splitarray_diff一起等作爲

$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 

Demo

0

嘗試玩PHP array_diff()功能。

array array_diff (array $array1 , array $array2 [, array $... ]) 

它比較array1對一種或多種其它陣列並返回array1中不存在於任何其它陣列的值。