本帖最后由 xiaolei1314555 于 2023-2-7 13:51 编辑
第一个二维数组:[PHP] 纯文本查看 复制代码 array(2) {
[0]=>
array(6) {
["id"]=> 1
["number"]=> "0001202203180001"
["goods_shelves"]=> "2H01JA01-03"
["goodsid"]=> "238756"
["name"]=> "帅帅矿岩石不粘炒锅32cm/个"
["qty"]=> "2.00"
}
[1]=>
array(6) {
["id"]=> 2
["number"]=> "0001202203180001"
["goods_shelves"]=> "2H01JA01-03"
["goodsid"]=> "238757"
["name"]=> "帅帅不粘炒锅/个"
["qty"]=> "2.00"
} [2]=>
array(6) {
["id"]=> 3
["number"]=> "0001202203180001"
["goods_shelves"]=> "2H01JA01-03"
["goodsid"]=> "245093"
["name"]=> "凤品优作全铸铁真不锈炒锅(有盖)32cm/个"
["qty"]=> "3.00"
}
}
第二个二维数组:[PHP] 纯文本查看 复制代码 array(4) {
[0]=>
array(6) {
["id"]=> 1
["number"]=> "0001202203180001"
["goods_shelves"]=> "2H01JA01-03"
["goodsid"]=> "206646"
["name"]=> "王麻子麦典麦饭石炒锅32cm/个"
["qty"]=> "36.00"
}
[1]=>
array(6) {
["id"]=> 2
["number"]=> "0001202203180001"
["goods_shelves"]=> "2H01JA01-03"
["goodsid"]=> "238757"
["name"]=> "帅帅不粘炒锅/个"
["qty"]=> "2.00"
}
[2]=>
array(6) {
["id"]=> 3
["number"]=> "0001202203180001"
["goods_shelves"]=> "2H01JA01-03"
["goodsid"]=> "345417"
["name"]=> "凤品优作全铸铁真不锈炖锅32cm/个"
["qty"]=> "22.00"
}
[3]=>
array(6) {
["id"]=> 4
["number"]=> "0001202203180001"
["goods_shelves"]=> "2H01JA01-03"
["goodsid"]=> "238756"
["name"]=> "帅帅矿岩石不粘炒锅32cm/个"
["qty"]=> "3.00"
}
}
怎么写个方法实现 2个二维数组 变成一个二维数组 格式如下:
[PHP] 纯文本查看 复制代码 array(4) {
[0]=>
array(6) {
["id"]=> 1
["number"]=> "0001202203180001"
["goods_shelves"]=> "2H01JA01-03"
["goodsid"]=> "206646"
["name"]=> "王麻子麦典麦饭石炒锅32cm/个"
["a_qty"]=> "0.00"
["b_qty"]=> "36.00"
["c_qty"]=> "0"
}
[1]=>
array(6) {
["id"]=> 2
["number"]=> "0001202203180001"
["goods_shelves"]=> "2H01JA01-03"
["goodsid"]=> "238757"
["name"]=> "帅帅不粘炒锅/个"
["a_qty"]=> "2.00"
["b_qty"]=> "2.00"
["c_qty"]=> "2.00"
}
[2]=>
array(6) {
["id"]=> 3
["number"]=> "0001202203180001"
["goods_shelves"]=> "2H01JA01-03"
["goodsid"]=> "345417"
["name"]=> "凤品优作全铸铁真不锈炖锅32cm/个"
["a_qty"]=> "0.00"
["b_qty"]=> "22.00"
["c_qty"]=> "0"
}
[3]=>
array(6) {
["id"]=> 4
["number"]=> "0001202203180001"
["goods_shelves"]=> "2H01JA01-03"
["goodsid"]=> "238756"
["name"]=> "帅帅矿岩石不粘炒锅32cm/个"
["a_qty"]=> "2.00"
["b_qty"]=> "3.00"
["c_qty"]=> "0"
}
[4]=>
array(6) {
["id"]=> 5
["number"]=> "0001202203180001"
["goods_shelves"]=> "2H01JA01-03"
["goodsid"]=> "245093"
["name"]=> "凤品优作全铸铁真不锈炒锅(有盖)32cm/个"
["a_qty"]=> "3.00"
["b_qty"]=> "0.00"
["c_qty"]=> "0"
}
}
数组1:里面的qty变成了a_qty ,数组2:里面的qty变成了b_qty ,生成新的二维数组的c_qty 是进行数组1和数组2 goodsid相同 a_qty 等于 b_qty 那么c_qty 就为 a_qty 如果不相等 或者有差异 那就是0
请问下 怎么在PHP 写个方法 实现上面的情况,请论坛大牛指点 |