<?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);
You have javascript disabled. You will not be able to edit any code.