我想比较 php 中的两个数组。我的数组看起来像这样
Array (
[0] => Array ( [Id] => 1 [row1] => 1458)
[1] => Array ( [Id] => 2 [row1] => 16)
[2] => Array ( [Id] => 3 [row1] => 115)
[3] => Array ( [Id] => 4 [row1] => 18)
[4] => Array ( [Id] => 5 [row1] => 13)
[5] => Array ( [Id] => 6 [row1] => 13)
[6] => Array ( [Id] => 7 [row1] => 131)
)
Array (
[0] => Array ( [Id] => 1 [row1] => 158)
[1] => Array ( [Id] => 2 [row1] => 165)
[2] => Array ( [Id] => 3 [row1] => 111)
[3] => Array ( [Id] => 4 [row1] => 186)
[4] => Array ( [Id] => 5 [row1] => 3)
)
首先,array1 的大小和 array2 的大小并不总是相等的。array1 中的 id 值可能存在也可能不存在于 array2,如果该值不存在,函数必须打印 array3 中的总索引,如
[someindex] => Array ( [Id] => 6 [row1] => 13 )
如果存在,函数应将 array1 的 row1 减去 array2 的 row1 并在 array3 中打印,如下所示
[someindex] => Array ( [Id] => 1 [row1] => 1300)
我的最终输出应该是,
Array (
[0] => Array ( [Id] => 1 [row1] => 1300)
[1] => Array ( [Id] => 2 [row1] => -149)
[2] => Array ( [Id] => 3 [row1] => 4)
[3] => Array ( [Id] => 4 [row1] => -168)
[4] => Array ( [Id] => 5 [row1] => 10)
[5] => Array ( [Id] => 6 [row1] => 13)
[6] => Array ( [Id] => 7 [row1] => 131)
)
任何人都可以帮助我解决这个问题。