遞迴
public function array_diff_assoc_recursive($packetData,$structure){
$difference = array();
foreach ($packetData as $k => $v) {
if (is_array($v)) {
if (!isset($structure[$k]) || !is_array($structure[$k])) {
$difference[$k] = $v;
} else {
$new_diff = $this->array_diff_assoc_recursive($v, $structure[$k]);
if (!empty($new_diff)){
$difference[$k] = $new_diff;
}
}
} else if (!array_key_exists($k, $structure) /* || $structure[$k] !== $v */) {
$difference[$k] = $v;
}
}
return $difference;
}
Last updated
Was this helpful?