Answers for "php count matching words in two strings"

PHP
0

php count matching words in two strings

$string1 = 'The dog and cat love each other';
$string2 = 'the dog pooped in the yard';
$arr1 = explode(" ",$string1 );
$arr2 = explode(" ",$string2 );
$result = array_intersect($arr1 , $arr2 ); //matched elements
$num = count($result); //number of matches
Posted by: Guest on October-12-2021

Browse Popular Code Answers by Language