Re: checking values between arrays
| From: | Andrei Zmievski | Date: | Fri, 07 Jul 2000 13:37:21 +0000 |
| Subject: | Re: checking values between arrays | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-5375@lists.php.net to get a copy of this message | ||
On Fri, 07 Jul 2000, Thomas Edison Jr. wrote:
> I got two arrays, both has got some words in different
> locations, how do i check wether any of the words in
> any location of the first array exist in any location
> of the second array?
>
> I tried running both arrays in multiple loops and
> putting an if condition, but it checks for only one
> word. If there are two common words, it doesn't give
> correct answer.
Try array_intersect() function.
<?
$a1 = array('red', 'green', 'blue');
$a2 = array('green', 'yellow', 'ochre');
$result = array_intersect($a1, $a2);
?>
$result should be array('green').
-Andrei
* Life may be expensive, but it includes an annual free trip around the sun. *