Created
March 23, 2013 11:55
-
-
Save karlgroves/5227442 to your computer and use it in GitHub Desktop.
Determines if two arrays are identical.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* compares two arrays to check if they're identical | |
* @param array $op1 the first array | |
* @param array $op2 the second array | |
* @return bool | |
*/ | |
function arrayIdentical($op1, $op2) { | |
if (count($op1) < count($op2)) { | |
return FALSE; | |
// $op1 < $op2 | |
} elseif (count($op1) > count($op2)) { | |
return FALSE; | |
// $op1 > $op2 | |
} | |
foreach ($op1 as $key => $val) { | |
if (!array_key_exists($key, $op2)) { | |
return FALSE; | |
// uncomparable | |
} elseif ($val < $op2[$key]) { | |
return FALSE; | |
} elseif ($val > $op2[$key]) { | |
return FALSE; | |
} | |
} | |
return TRUE; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment