Remove duplicates in a php loop - only addup values from unique ID # -
ive seen many posts explaining use array_unique
dont think work scenario...
i have multiple results in report, if notice picture st/ot has duplicate 1.50
, 2.00
values because each sql entry has 1.50
, 2.00
each st_ot cell
at bottom totals up, $stot_total += $data["stot"];
. adding total. want total of 1.50 + 2.00 (3.50)
. dont want add duplicates.
all ones 1.50
have same id#
well, if theres way add values id#1
, id#2
, id#3
, on... work me...
i apologize horrible post... question regarding st/ot values **
foreach($dary $data){ $stot_total += $data["stot"]; }
a simple modification of answer @awei should trick you:
<?php $stot_bucket = array(); foreach($dary $data) { // since don't need access values in multi-dimensional way, combine 2 keys 1 make final summing simpler $stot_bucket[$data["id"] . $data["stot"]] = $data["stot"]; } $stot_total = array_sum($stot_bucket); ?>
Comments
Post a Comment