0

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.

5
Contributors
5
Replies
6
Views
5 Years
Discussion Span
Last Post by stanley87
0

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

0

Hi,

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

<?php
$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/>";
}

?>
0

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.

0

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

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.