I have a large array with some data. I was trying to make only one function to return the sum of each value from the beginning of the month until the end of the month for each group.
I have created a function that returns the total of a "key", but I have to repeat myself all the time for each key. Is it possible to make multiple return values with only one function like putting them in an array?
// I'm using this function for returning the value
function kontratat_tot_grupi($date, $grup_name, $value) {
$tot_grupi = $date[$grup_name][$value];
return $tot_grupi;
}
// And here I'm using the function on grup_a in a 'while' loop
$tot_grup_a += kontratat_tot_grupi($date, "grup_a", "luce");
// This is a piece from my array
Array
(
[2016-05-02] => Array
(
[grup_a] => Array
(
[luce] => 4
[ctr_ok] => 3
[ctr_tot] => 7
[ctr_ko] => 4
[gas] => 3
[ore] => 30.5
)
[grup_b] => Array
(
[luce] => 3
[ctr_ko] => 4
[ctr_tot] => 6
[gas] => 3
[ctr_ok] => 2
[ore] => 47
)
[grup_c] => Array
(
[luce] => 6
[ctr_ko] => 1
[ctr_tot] => 8
[ctr_gia_cliente] => 1
[ctr_ok] => 6
[gas] => 2
[ore] => 24
)
[grup_d] => Array
(
[luce] => 4
[ctr_ok] => 4
[ctr_tot] => 8
[gas] => 4
[ctr_ko] => 4
[ore] => 30
)
[grup_e] => Array
(
[luce] => 9
[ctr_ko] => 11
[ctr_tot] => 17
[gas] => 8
[ctr_ok] => 6
[ore] => 35
)
[grup_f] => Array
(
[luce] => 1
[ctr_ok] => 2
[ctr_tot] => 2
[gas] => 1
[ore] => 36
)
[grup_g] => Array
(
[luce] => 5
[ctr_ko] => 1
[ctr_tot] => 7
[ctr_ok] => 6
[gas] => 2
[ore] => 22
)
)
[2016-05-03] => Array
(
[grup_a] => Array
(
[luce] => 6
[ctr_ok] => 6
[ctr_tot] => 10
[gas] => 4
[ctr_ko] => 4
[ore] => 33.5
)
[grup_b] => Array
(
[luce] => 6
[ctr_ok] => 4
[ctr_tot] => 8
[ctr_ko] => 2
[gas] => 2
[ctr_att_green] => 2
[ore] => 36
)
[grup_c] => Array
(
[luce] => 6
[ctr_ok] => 4
[ctr_tot] => 9
[gas] => 3
[ctr_ko] => 5
[ore] => 36
)
[grup_d] => Array
(
[luce] => 5
[ctr_ko] => 2
[ctr_tot] => 10
[gas] => 5
[ctr_ok] => 8
[ore] => 42
)
[grup_e] => Array
(
[gas] => 2
[ctr_ok] => 3
[ctr_tot] => 3
[luce] => 1
[ore] => 23
)
[grup_f] => Array
(
[luce] => 1
[ctr_ko] => 2
[ctr_tot] => 2
[gas] => 1
[ore] => 36
)
[grup_g] => Array
(
[luce] => 2
[ctr_ok] => 1
[ctr_tot] => 3
[ctr_gia_cliente] => 2
[gas] => 1
[ore] => 27.3
)
)
[2016-05-04] => Array
(
[grup_a] => Array
(
[luce] => 6
[ctr_ko] => 1
[ctr_tot] => 11
[ctr_ok] => 10
[gas] => 5
[ore] => 32
)
[grup_b] => Array
(
[luce] => 5
[ctr_ok] => 10
[ctr_tot] => 11
[gas] => 6
[ctr_ko] => 1
[ore] => 33.4
)
[grup_c] => Array
(
[luce] => 8
[ctr_ok] => 15
[ctr_tot] => 15
[gas] => 7
[ore] => 36
)
[grup_d] => Array
(
[luce] => 5
[ctr_ok] => 5
[ctr_tot] => 8
[gas] => 3
[ctr_att_egeo] => 1
[ctr_ko] => 2
[ore] => 47
)
[grup_e] => Array
(
[luce] => 4
[ctr_ok] => 5
[ctr_tot] => 5
[gas] => 1
[ore] => 36
)
[grup_f] => Array
(
[luce] => 3
[ctr_ko] => 5
[ctr_tot] => 6
[gas] => 3
[ctr_ok] => 1
[ore] => 33
)
[grup_g] => Array
(
[luce] => 8
[ctr_ok] => 12
[ctr_tot] => 12
[gas] => 4
[ore] => 36
)
)