3v4l.org

run code in 200+ php & hhvm versions
<?php // Your code here! // グルーピングキー1 $group1 = 'knrno'; // グルーピングキー2 $group2 = 'taxcd'; // 足す金額 $kin = 'gokin'; $parm = [ '0' => [ 'knrno' => '0001004_20181210__0_100_20190101', 'hancd' => '0001004', 'hannm' => '水戸上中妻', 'ssmdt' => '20181210', 'sekno' => '000382633', 'seiux' => 0, 'hanpos' => 311-4143, 'hanaddr1' => '水戸市大塚町1261-3', 'hanaddr2' => '', 'hanaddr3' => '', 'skmbmn' => 'VF課', 'skmtel' => '029-240-7722', 'skmfax' => '029-219-2215', 'shudt' => '2018/12/02', 'hinnm' => 'だいこん', 'denno' => '2697850', 'suryo' => '-100.00', 'gokin' => 500, 'shzei' => -800, 'gsykei' => 10279, 'gshzei' => 821, 'ggokin' => 11100, 'skymd' => '2019年01月01日', 'title' => '請求書', 'jahno' => 1, 'nowdate' => '2019年07月12日', 'reprint' => 0, 'dspod' => 0, 'taxcd' => 'A' , 'hbydt' => 20181202, ], '1' => [ 'knrno' => '0001004_20181210__0_100_20190101', 'hancd' => '0001004', 'hannm' => '水戸上中妻', 'ssmdt' => '20181210', 'sekno' => '000382633', 'seiux' => 0, 'hanpos' => 311-4143, 'hanaddr1' => '水戸市大塚町1261-3', 'hanaddr2' => '', 'hanaddr3' => '', 'skmbmn' => 'VF課', 'skmtel' => '029-240-7722', 'skmfax' => '029-219-2215', 'shudt' => '2018/12/02', 'hinnm' => 'だいこん', 'denno' => '2697850', 'suryo' => '-100.00', 'gokin' => 700, 'shzei' => -800, 'gsykei' => 10279, 'gshzei' => 821, 'ggokin' => 11100, 'skymd' => '2019年01月01日', 'title' => '請求書', 'jahno' => 1, 'nowdate' => '2019年07月12日', 'reprint' => 0, 'dspod' => 0, 'taxcd' => 'A' , 'hbydt' => 20181202, ], '3' => [ 'knrno' => '0001004_20181210__0_100_20190101', 'hancd' => '0001004', 'hannm' => '水戸上中妻', 'ssmdt' => '20181210', 'sekno' => '000382633', 'seiux' => 0, 'hanpos' => 311-4143, 'hanaddr1' => '水戸市大塚町1261-3', 'hanaddr2' => '', 'hanaddr3' => '', 'skmbmn' => 'VF課', 'skmtel' => '029-240-7722', 'skmfax' => '029-219-2215', 'shudt' => '2018/12/02', 'hinnm' => 'だいこん', 'denno' => '2697850', 'suryo' => '-100.00', 'gokin' => 1000, 'shzei' => -800, 'gsykei' => 10279, 'gshzei' => 821, 'ggokin' => 11100, 'skymd' => '2019年01月01日', 'title' => '請求書', 'jahno' => 1, 'nowdate' => '2019年07月12日', 'reprint' => 0, 'dspod' => 0, 'taxcd' => 'B' , 'hbydt' => 20181202, ] ]; $aaa = 0; $result = []; foreach($parm as $no => $value){ // 管理ID $groupKey1 = $value[$group1]; // 税率 $groupKey2 = $value[$group2]; $result[$groupKey1][$groupKey2] = $value[$kin]; // var_dump($groupKey1); // var_dump($groupKey2); // var_dump($value[$kin]); // $ihara = array_sum($result); } var_dump($result); // $result[$groupKey1][$groupKey2] += $values[$kin]; // } // var_dump($result); ?>
based on rMPN4
Output for 7.1.25 - 7.4.0alpha2
array(1) { ["0001004_20181210__0_100_20190101"]=> array(2) { ["A"]=> int(700) ["B"]=> int(1000) } }