PHP array math, removing dublicates and addition of array rows -
okay, trying accomplish rather simple. don't know how, , hope can help.
i have array 2 values, userid , transaction value. userid not unique, , list/array of same values, "summed up". meaning: if userid has more occurrences, 2nd value (the transaction) added together. post example.
$a = array( 1 => 1, 1 => 2, 2 => 3, 2 => -17 );
the result after running whatever function needed, is:
$a = array( 1 => 3, 2 => -14 );
so no dublicate userid's, , transaction values added 1 entry of userid.
i getting these values sql database, if can solve sql view or something, go valid reply :-)
thanks lot in advance!
in sql if columns say, id , value,
select sum(value) table_name grouping id
php arrays addition
No comments:
Post a Comment