Created
February 1, 2018 10:20
-
-
Save itsKnight847/af7d502d7f264f725aa168cc5cb29cb1 to your computer and use it in GitHub Desktop.
recursive array check PHP
This file contains hidden or 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
/** | |
* check recursive array and spot the diffrence | |
* @param $_first_array | |
* @param $_second_array | |
* @return array | |
*/ | |
private function recursive_array_check($_first_array, $_second_array) { | |
$diff = []; | |
foreach($_first_array as $k => $v) { | |
if(is_array($v) && isset($_second_array[$k])){ | |
$_diff = self::recursive_array_check($v, $_second_array[$k]); | |
if( !empty($_diff) ) { | |
$diff[$k] = $_diff; | |
} | |
} else if(is_string($v) && !in_array($v, $_second_array)) { | |
$diff[$k] = $v . " missing from second array"; | |
} else if(!is_numeric($k) && !array_key_exists($k, $_second_array)) { | |
$diff[$k] = "Missing from second array"; | |
} | |
} | |
return $diff; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment