php 多维数组相同键值处理合并

  • Post author:
  • Post category:php




一、前言

在实际情况中,有时需要针对多维数组相同键值作相应的处理(四则运算、比较大小等)后才能够使用到实际情况中,现给出三维数组(多维数组可相应拓展)任意多个相同键值处理的函数,以备查阅。



二、代码

 1 <?php
 2 //任意多个相同键值的数组合并
 3 //预先将所要合并的数组组装成一个新的数组
 4 
 5     $arr = array(
 6       '1' => array(
 7             '1' => array(
 8                 "channelName"         => "渠道1",
 9                 "firstRegisterTime"   => "2018-12-20 10:23:57",
10                 "firstChargeNum"      => 168,
11             ),
12             '2' => array(
13                 "channelName"         => "渠道2",
14                 "firstRegisterTime"   => "2018-12-20 10:23:57",
15                 "firstChargeNum"      => 127,
16             ),
17             '3' => array(
18                 "channelName"         => "渠道3",
19                 "firstRegisterTime"   => "2018-12-10 11:23:57",
20                 "firstChargeNum"      => 69,
21             ),
22         ),
23       '2' => array(
24             '1' => array(
25                 "channelName"         => "渠道1",
26                 "firstRegisterTime"   => "2017-12-29 10:23:57",
27                 "firstChargeNum"      => 798,