Skip to content

Instantly share code, notes, and snippets.

@kevinmarks
Created March 20, 2019 16:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kevinmarks/b7e6a24d21d1d86634c7ede1ed814ea5 to your computer and use it in GitHub Desktop.
Save kevinmarks/b7e6a24d21d1d86634c7ede1ed814ea5 to your computer and use it in GitHub Desktop.
comparing 2 nested arrays in PHP
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