May i know how to matching 2 array keywords?

e.g I have
1st array keyword like kfc,mcd,fastfood,etc
2st array keyword like kfc,mcd

If i want to get the matching keywords among these 2 arrays, how to i write the matching code?

Thank advance for your help.

Use foreach on the 2nd array and then compare the results in the foreach against the first array using in_array


Here is the simple example for both of the responses above.

$first_ar = array('one','two','three','four','five','six','seven');
$second_ar = array('two','ten','eleven','five','twelve','nine','three');
	       $result = array_intersect($first_ar, $second_ar);
foreach($result as $something){
	echo "Matched: ".$something."<br/>";

Member Avatar


Yep like veedoo. However, be aware that this is case sensitive:

'One' and 'one' will not match.

If you want a case-insensitive match, you need to use something like array_map and choose a suitable function like strtolower or mb_strtolower (for UTF-8 compliance). DO this for each array and then do array_intersect.

Thanks guys for you all info,i have been done some simple matching way regarding your guys help.Anyway,thanks again for you guys.