仅从一个php函数返回多个值

时间:2016-05-28 22:18:03

标签: php arrays function

我有一个包含一些数据的大型数组。我试图只做一个函数来返回每个值的总和,从月份的乞讨到每个月的月末。我创建了一个函数,返回一个“键”的总和,但我必须为每个键重复我的自我。是否可以只使用一个函数进行多次返回,例如将它们放入数组中?

//I'am using this function for returnig the value
function kontratat_tot_grupi($date,$grup_name,$value){
    $tot_grupi = $date[$grup_name][$value];
    return $tot_grupi;
}

//and here i'am 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
                )

        )

0 个答案:

没有答案