Created
March 20, 2019 16:02
-
-
Save kevinmarks/b7e6a24d21d1d86634c7ede1ed814ea5 to your computer and use it in GitHub Desktop.
comparing 2 nested arrays in PHP
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
function diffdata($legacy,$shiny) { | |
$delta=array(); | |
foreach ($legacy as $key => $oldval){ | |
$newval = $shiny[$key]; | |
if ($oldval==$newval){ | |
$delta[$key]="✅"; | |
} else if (is_array($oldval) && is_array($newval)){ | |
$delta[$key] = diffdata($oldval,$newval); | |
} else { | |
$delta[$key]="❌ expected: $oldval<br>❌ returned: $newval"; | |
} | |
} | |
return $delta; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment