3v4l.org

run code in 300+ PHP versions simultaneously
<?php $input_array = [ ["cust_id" => 1006, "no_of_subs" => 2, "dlv_id" => 1000], ["cust_id" => 1011, "no_of_subs" => 3, "dlv_id" => 1000], ["cust_id" => 1012, "no_of_subs" => 5, "dlv_id" => 1001], ["cust_id" => 1013, "no_of_subs" => 6, "dlv_id" => 1001] ]; $dlv_id = array_column($input_array, 'dlv_id', 'cust_id'); // get all no_of_subs maintaining the cust_id as index $no_of_subs = array_column($input_array, 'no_of_subs', 'cust_id'); $output = array(); foreach ($dlv_id as $key => $value) { if (isset($output[$value]['dlv_id'])) { $output[$value]['dlv_id'] += $no_of_subs[$key]; } else { $output[$value]['dlv_id'] += $no_of_subs[$key]; } } var_export($output);
Output for 8.0.0 - 8.0.30, 8.1.0 - 8.1.33, 8.2.0 - 8.2.29, 8.3.0 - 8.3.28, 8.4.1 - 8.4.14, 8.5.0
Warning: Undefined array key 1000 in /in/irHJT on line 21 Warning: Undefined array key "dlv_id" in /in/irHJT on line 21 Warning: Undefined array key 1001 in /in/irHJT on line 21 Warning: Undefined array key "dlv_id" in /in/irHJT on line 21 array ( 1000 => array ( 'dlv_id' => 5, ), 1001 => array ( 'dlv_id' => 11, ), )
Output for 8.4.15
/bin/php-8.4.15: /usr/lib/libm.so.6: version `GLIBC_2.38' not found (required by /bin/php-8.4.15) /bin/php-8.4.15: /usr/lib/libm.so.6: version `GLIBC_2.35' not found (required by /bin/php-8.4.15) /bin/php-8.4.15: /usr/lib/libc.so.6: version `GLIBC_2.34' not found (required by /bin/php-8.4.15) /bin/php-8.4.15: /usr/lib/libc.so.6: version `GLIBC_2.38' not found (required by /bin/php-8.4.15)
Process exited with code 1.
Output for 5.6.38, 7.1.0 - 7.1.25, 7.2.0 - 7.2.33, 7.3.0 - 7.3.31, 7.4.0 - 7.4.33
Notice: Undefined offset: 1000 in /in/irHJT on line 21 Notice: Undefined index: dlv_id in /in/irHJT on line 21 Notice: Undefined offset: 1001 in /in/irHJT on line 21 Notice: Undefined index: dlv_id in /in/irHJT on line 21 array ( 1000 => array ( 'dlv_id' => 5, ), 1001 => array ( 'dlv_id' => 11, ), )
Output for 7.3.32 - 7.3.33
array ( 1000 => array ( 'dlv_id' => 5, ), 1001 => array ( 'dlv_id' => 11, ), )

preferences:
202.42 ms | 410 KiB | 5 Q