I have been working on this problem for a couple days now. I would like to make an array that contains a list of user id's with the sum of value1 and value2 from the list of data below.
User ID value1 Value2
1 21 2
2 2 6
3 4 43
1 3 9
2 17 8
1 12 28
Here is an amalgamation of my various attempts. It is all wrong, but conveys what I am trying to do.
$members_list = array();
if(!in_array($user_id, $members_list)){
array_push($members_list, $user_id);
}
foreach($data_table as $data_row){
if($user_id == $data_row['$user_id']) {
$members_list[$_user_id]['total'] = $members_list[$user_id]['total'] + $data_row['value1'] + $data_row['value2'];
}
}
I am trying to teach myself how to program and probably lacking a fundamental understanding of how to organise and loop through multi-dimensional arrays. Hoping someone can help me clear this up. Thanks in advance.
var_dump($data_table)
? – Dinistro Oct 21 '14 at 13:34