我使用这段代码:
$new = array(
"123" => "a",
"456" => "b"
);
$old = array(
"123" => "a",
"456" => "b"
);
然后$new
数组变成这样:
$new = array(
"456" => "b",
"123" => "c",
"789" => "e"
);
如您所见,$new
数组的数量增加了,元素的顺序发生了变化,键的值123
也发生了变化。我需要将$new
数组与$old
数组进行比较,并且只捕获对键值所做的更改,123
而不关心元素的顺序和数量。我试过:
$result = array_diff( $new, $old );
print_r( $result );
输出 :
Array ( [123] => c [789] => e )