Compare Array Elements

From: Date: Sat, 03 Jan 2004 14:50:25 +0000
Subject: Compare Array Elements
Groups: php.general 
Request: Send a blank email to php-general+get-173682@lists.php.net to get a copy of this message
I am a novice, I am sure this is pretty simple... I have two arrays of integers, equal length. The arrays elements consists of the integers 0 through 9. The order of the numbers in the arrays should always be different. Example 1: Is ok xArray: 2 9 6 0 1 3 4 5 8 7 yArray: 3 7 1 9 0 8 6 2 4 5 Example 2: Is not ok - the element "7" is in the same position in both arrays. xArray: 2 9 6 0 7 3 4 5 8 1 yArray: 3 5 1 9 7 8 6 2 4 0 I need a snippet that will compare the value of each element in each position and call a function to create a new array if the compare evaluates to true. I assume that a foreach is the way to go, but I can't seem to find the right syntax for it. ------- if foreach (xArray as $x) == (yArray as $y) { new_yArray (); } ------ I know this isn't correct, but in idiot terms, it is what I want to do... a test/compare. Of course the compare should stop and call the function the moment it evaluates to true at any given position. Maybe I should be using a "for" loop? (again, not a clue) Thanks anyone!

« previous php.general (#173682) next »