function _cmp_deeply($have, $exp, $path = '') { if (is_array($exp)) { if (!is_array($have)) { return _diff($path, _repl($have), $path, _repl($exp)); } $gk = array_keys($have); $ek = array_keys($exp); $mc = max(count($gk), count($ek)); for ($el = 0; $el < $mc; $el++) { # One array shorter than the other? if ($el >= count($ek)) { return _diff(_idx($gk[$el], $path), _repl($have[$gk[$el]]), 'missing', 'nothing'); } else { if ($el >= count($gk)) { return _diff('missing', 'nothing', _idx($ek[$el], $path), _repl($exp[$ek[$el]])); } } # Keys differ? if ($gk[$el] != $ek[$el]) { return _diff(_idx($gk[$el], $path), _repl($have[$gk[$el]]), _idx($ek[$el], $path), _repl($exp[$ek[$el]])); } # Recurse $rc = _cmp_deeply($have[$gk[$el]], $exp[$ek[$el]], _idx($gk[$el], $path)); if (!is_null($rc)) { return $rc; } } } elseif (is_numeric($have) && is_numeric($exp)) { // why trim - good question, but it helps? if (0 + trim($have) !== 0 + trim($exp)) { return _diff($path, _repl($have), $path, _repl($exp)); } } else { # Default to serialize hack if (serialize($have) != serialize($exp)) { return _diff($path, _repl($have), $path, _repl($exp)); } } return null; }
function _cmp_deeply($have, $exp, $path = '') { if (is_array($exp)) { //diag("using recursive cmp in is_deeply"); if (!is_array($have)) { return _diff($path, _repl($have), $path, _repl($exp)); } $gk = array_keys($have); $ek = array_keys($exp); $mc = max(count($gk), count($ek)); for ($el = 0; $el < $mc; $el++) { # One array shorter than the other? if ($el >= count($ek)) { return _diff(_idx($gk[$el], $path), _repl($have[$gk[$el]]), 'missing', 'nothing'); } else { if ($el >= count($gk)) { return _diff('missing', 'nothing', _idx($ek[$el], $path), _repl($exp[$ek[$el]])); } } # Keys differ? if ($gk[$el] != $ek[$el]) { return _diff(_idx($gk[$el], $path), _repl($have[$gk[$el]]), _idx($ek[$el], $path), _repl($exp[$ek[$el]])); } # Recurse $rc = _cmp_deeply($have[$gk[$el]], $exp[$ek[$el]], _idx($gk[$el], $path)); if (!is_null($rc)) { return $rc; } } } else { # Default to serialize hack //diag("using serialize() in is_deeply"); if (serialize($have) != serialize($exp)) { return _diff($path, _repl($have), $path, _repl($exp)); } } return null; }