3v4l.org

run code in 300+ PHP versions simultaneously
<?php $arr1 = array ( 0 => array ( 'Team' => 'Midtjylland', 'country' => 'dk', 'clubid' => '2', 'P' => '26', 'W' => '21', 'D' => '2', 'L' => '3', 'F' => '42', 'A' => '14', 'GD' => '28', 'Pts' => '65', 'form' => 'W,L,W,W,W,W,L,W,W,W,W,W,W,W,W,L,D,W,W,W,D,W,W,W,W,W', ), 1 => array ( 'Team' => 'København', 'country' => 'dk', 'clubid' => '1', 'P' => '26', 'W' => '18', 'D' => '2', 'L' => '6', 'F' => '47', 'A' => '29', 'GD' => '18', 'Pts' => '56', 'form' => 'W,W,L,W,D,L,W,W,W,W,L,W,W,W,L,W,D,L,L,W,W,W,W,W,W,W', ), 2 => array ( 'Team' => 'AGF', 'country' => 'dk', 'clubid' => '9', 'P' => '26', 'W' => '14', 'D' => '5', 'L' => '7', 'F' => '42', 'A' => '28', 'GD' => '14', 'Pts' => '47', 'form' => 'W,W,D,L,D,W,W,D,W,W,W,W,L,L,L,W,W,W,W,W,W,D,L,L,L,D', ), 3 => array ( 'Team' => 'Brøndby', 'country' => 'dk', 'clubid' => '4', 'P' => '26', 'W' => '13', 'D' => '3', 'L' => '10', 'F' => '47', 'A' => '37', 'GD' => '10', 'Pts' => '42', 'form' => 'L,W,D,W,L,W,D,L,L,L,W,W,W,W,W,L,L,W,L,L,W,W,L,W,D,W', ), 4 => array ( 'Team' => 'Nordsjælland', 'country' => 'dk', 'clubid' => '7', 'P' => '26', 'W' => '12', 'D' => '5', 'L' => '9', 'F' => '48', 'A' => '35', 'GD' => '13', 'Pts' => '41', 'form' => 'L,W,D,W,W,W,W,L,D,W,D,L,L,W,D,L,W,L,W,L,W,D,L,W,L,W', ), 5 => array ( 'Team' => 'AaB', 'country' => 'dk', 'clubid' => '6', 'P' => '26', 'W' => '11', 'D' => '5', 'L' => '10', 'F' => '44', 'A' => '33', 'GD' => '11', 'Pts' => '38', 'form' => 'L,D,W,L,W,W,L,D,D,W,D,L,W,W,W,L,L,L,W,W,L,W,L,W,D,L', ), 6 => array ( 'Team' => 'Randers', 'country' => 'dk', 'clubid' => '8', 'P' => '26', 'W' => '10', 'D' => '5', 'L' => '11', 'F' => '39', 'A' => '35', 'GD' => '4', 'Pts' => '35', 'form' => 'L,L,D,L,W,D,W,L,W,L,D,W,L,L,W,W,W,W,W,L,L,L,W,D,D,L', ), 7 => array ( 'Team' => 'Horsens', 'country' => 'dk', 'clubid' => '10', 'P' => '26', 'W' => '10', 'D' => '4', 'L' => '12', 'F' => '25', 'A' => '44', 'GD' => '-19', 'Pts' => '34', 'form' => 'W,W,W,L,L,L,W,D,W,L,W,D,L,W,L,D,L,D,W,L,L,L,W,L,W,L', ), 8 => array ( 'Team' => 'OB', 'country' => 'dk', 'clubid' => '3', 'P' => '26', 'W' => '9', 'D' => '6', 'L' => '11', 'F' => '34', 'A' => '30', 'GD' => '4', 'Pts' => '33', 'form' => 'W,L,D,D,D,L,L,D,L,L,L,W,W,L,W,W,L,W,D,D,L,W,W,L,W,L', ), 9 => array ( 'Team' => 'Lyngby', 'country' => 'dk', 'clubid' => '34', 'P' => '26', 'W' => '9', 'D' => '5', 'L' => '12', 'F' => '31', 'A' => '45', 'GD' => '-14', 'Pts' => '32', 'form' => 'D,L,L,L,W,L,W,D,D,D,W,L,W,L,D,W,W,L,L,W,L,L,W,L,L,W', ), 10 => array ( 'Team' => 'SønderjyskE', 'country' => 'dk', 'clubid' => '11', 'P' => '26', 'W' => '6', 'D' => '9', 'L' => '11', 'F' => '31', 'A' => '44', 'GD' => '-13', 'Pts' => '27', 'form' => 'D,L,D,L,L,W,L,W,L,D,L,L,L,L,W,W,D,D,D,L,D,D,L,W,D,W', ), 11 => array ( 'Team' => 'Hobro', 'country' => 'dk', 'clubid' => '13', 'P' => '26', 'W' => '3', 'D' => '14', 'L' => '9', 'F' => '25', 'A' => '35', 'GD' => '-10', 'Pts' => '23', 'form' => 'D,W,D,D,L,L,D,D,D,L,D,L,D,L,L,L,D,W,L,D,D,L,W,D,D,D', ), 12 => array ( 'Team' => 'Esbjerg', 'country' => 'dk', 'clubid' => '5', 'P' => '26', 'W' => '4', 'D' => '6', 'L' => '16', 'F' => '22', 'A' => '44', 'GD' => '-22', 'Pts' => '18', 'form' => 'L,D,D,L,L,W,L,L,L,W,L,D,L,L,L,D,W,L,L,D,W,L,L,L,D,L', ), 13 => array ( 'Team' => 'Silkeborg', 'country' => 'dk', 'clubid' => '33', 'P' => '26', 'W' => '3', 'D' => '7', 'L' => '16', 'F' => '31', 'A' => '55', 'GD' => '-24', 'Pts' => '16', 'form' => 'D,L,W,D,D,L,L,W,L,L,L,L,D,W,L,L,L,L,L,D,D,D,L,L,L,L', ), ); $arr2 = array ( 0 => array ( 'Team' => 'SønderjyskE', 'country' => 'dk', 'clubid' => '11', 'P' => '6', 'W' => '3', 'D' => '2', 'L' => '1', 'F' => '6', 'A' => '5', 'GD' => '1', 'Pts' => '11', 'form' => 'D,D,W,W,L,W', ), 1 => array ( 'Team' => 'Silkeborg', 'country' => 'dk', 'clubid' => '33', 'P' => '6', 'W' => '3', 'D' => '1', 'L' => '2', 'F' => '12', 'A' => '4', 'GD' => '8', 'Pts' => '10', 'form' => 'W,W,L,L,D,W', ), 2 => array ( 'Team' => 'OB', 'country' => 'dk', 'clubid' => '3', 'P' => '6', 'W' => '3', 'D' => '1', 'L' => '2', 'F' => '9', 'A' => '12', 'GD' => '-3', 'Pts' => '10', 'form' => 'L,D,W,W,W,L', ), 3 => array ( 'Team' => 'Lyngby', 'country' => 'dk', 'clubid' => '34', 'P' => '6', 'W' => '0', 'D' => '2', 'L' => '4', 'F' => '3', 'A' => '9', 'GD' => '-6', 'Pts' => '2', 'form' => 'D,L,L,L,D,L', ), ); foreach ($arr2 as $array) { $result[$array['clubid']] = $array; } foreach ($arr1 as $array) { if (isset($result[$array['clubid']])) { $result[$array['clubid']]['form'] .= ',' . $array['form']; foreach (['P', 'W', 'D', 'L', 'F', 'A', 'GD', 'Pts'] as $tally) { $result[$array['clubid']][$tally] += $array[$tally]; } } } var_export($result);

preferences:
82.67 ms | 404 KiB | 5 Q