<?php
$qp = [
['Nsd_id' => "1@2@3@4@5", 'Nsd_amount' => "0@0@0@20000@0"],
['Nsd_id' => "1@2@3@4@5", 'Nsd_amount' => "0@0@12000@0@0"],
['Nsd_id' => "1@2@3@4@5", 'Nsd_amount' => "0@0@0@10000@0"],
['Nsd_id' => "1@2@3@4@5", 'Nsd_amount' => "0@0@10000@0@0"],
['Nsd_id' => "1@2@3@4@5@12", 'Nsd_amount' => "0@0@10000@0@0@1000"],
['Nsd_id' => "1@2@3@4@5@12@14@15", 'Nsd_amount' => "0@0@8000@0@0@0@0@0"],
['Nsd_id' => "1@2@3@4@5@12@14@15", 'Nsd_amount' => "0@0@0@0@0@0@13000@0"],
['Nsd_id' => "1@2@3@4@5@12@14@15", 'Nsd_amount' => "0@2500@0@3900@0@0@20000@0"],
['Nsd_id' => "1@2@3@4@5@12@14@15", 'Nsd_amount' => "0@0@5000@0@0@0@0@0"],
['Nsd_id' => "1@2@3@4@5@12@14@15", 'Nsd_amount' => "0@0@5000@0@0@1000@0@0"],
['Nsd_id' => "1@2@3@4@5@12@14@15", 'Nsd_amount' => "0@0@2000@0@0@500@0@0"],
['Nsd_id' => "1@2@3@4@5@12@14@15", 'Nsd_amount' => "0@0@0@0@0@0@4000@0"],
];
$nsdIds = [];
$result = [];
foreach ($qp as $key => $value) {
// exploding Nsd_ids
$nsdTemp = explode("@", $value['Nsd_id']);
// exploding nsd_amounts
$nsdAmount = explode("@", $value['Nsd_amount']);
// saving all new nsd ids and only keep unique nsd ids
$nsdIds = array_unique(array_merge($nsdIds, $nsdTemp));
// I am now combining keeping nsd id as key and nsd amount as its value
$temp1 = array_combine($nsdTemp, $nsdAmount);
foreach ($nsdIds as $value1) {
// for latest php version
// $temp1 contains keys of nsd ids
// value1 contains nsdids we are sure that it will be in nsdids as we are already merging those ids
// then fetching amounf for that nsdids
$result[$value1] = ($result[$value1] ?? 0) + $temp1[$value1];
// for php version less than 7
// $result[$value1] = (!empty($result[$value1]) ? $result[$value1] : 0) + $result[$temp1[$value1]];
}
}
print_r($result);die;
- Output for git.master, git.master_jit, rfc.property-hooks
- Array
(
[1] => 0
[2] => 2500
[3] => 52000
[4] => 33900
[5] => 0
[12] => 2500
[14] => 37000
[15] => 0
)
This tab shows result from various feature-branches currently under review by the php developers. Contact me to have additional branches featured.
Active branches
Archived branches
Once feature-branches are merged or declined, they are no longer available. Their functionality (when merged) can be viewed from the main output page
preferences:
124.59 ms | 405 KiB | 5 Q