関数内でforeachを使用していますが、正しい値を出力できませんでした。foreach関数内で値が出力されない
私は機能
//this is only a small part of it because it is very large
Array
(
[2016-05-02] => Array
(
[grup_1] => Array
(
[luce] => 4
[ctr_ok] => 3
[ctr_tot] => 7
[ctr_ko] => 4
[gas] => 3
[ore] => 30.5
)
[grup_2] => Array
(
[luce] => 3
[ctr_ko] => 4
[ctr_tot] => 6
[gas] => 3
[ctr_ok] => 2
[ore] => 47
)
[grup_3] => Array
(
[luce] => 6
[ctr_ko] => 1
[ctr_tot] => 8
[ctr_gia_cliente] => 1
[ctr_ok] => 6
[gas] => 2
[ore] => 24
)
[grup_4] => Array
(
[luce] => 4
[ctr_ok] => 4
[ctr_tot] => 8
[gas] => 4
[ctr_ko] => 4
[ore] => 30
)
[grup_5] => Array
(
[luce] => 9
[ctr_ko] => 11
[ctr_tot] => 17
[gas] => 8
[ctr_ok] => 6
[ore] => 35
)
[grup_6] => Array
(
[luce] => 1
[ctr_ok] => 2
[ctr_tot] => 2
[gas] => 1
[ore] => 36
)
[grup_7] => Array
(
[luce] => 5
[ctr_ko] => 1
[ctr_tot] => 7
[ctr_ok] => 6
[gas] => 2
[ore] => 22
)
)
[2016-05-03] => Array
(
[grup_1] => Array
(
[luce] => 6
[ctr_ok] => 6
[ctr_tot] => 10
[gas] => 4
[ctr_ko] => 4
[ore] => 33.5
)
[grup_2] => Array
(
[luce] => 6
[ctr_ok] => 4
[ctr_tot] => 8
[ctr_ko] => 2
[gas] => 2
[ctr_att_green] => 2
[ore] => 36
)
[grup_3] => Array
(
[luce] => 6
[ctr_ok] => 4
[ctr_tot] => 9
[gas] => 3
[ctr_ko] => 5
[ore] => 36
)
[grup_4] => Array
(
[luce] => 5
[ctr_ko] => 2
[ctr_tot] => 10
[gas] => 5
[ctr_ok] => 8
[ore] => 42
)
[grup_5] => Array
(
[gas] => 2
[ctr_ok] => 3
[ctr_tot] => 3
[luce] => 1
[ore] => 23
)
[grup_6] => Array
(
[luce] => 1
[ctr_ko] => 2
[ctr_tot] => 2
[gas] => 1
[ore] => 36
)
[grup_7] => Array
(
[luce] => 2
[ctr_ok] => 1
[ctr_tot] => 3
[ctr_gia_cliente] => 2
[gas] => 1
[ore] => 27.3
)
)
そして、ここで処理される配列がctr_tot
キー
function kontratat_tot($grup_name){
$total = 0;
foreach ($kontrata as $date => $grup){
if($grup[$grup_name]['ctr_tot'] != 0){
$total += $grup[$grup_name]['ctr_tot'];
}
}
return $total;
}
と、ここで私は
kontratat_tot("grup_1");
関数を呼び出すの合計を集める機能である必要があり
私は私のproblのための解決策を見つけるために過去3時間を探していますしかし、私は立ち往生していて、ソリューションが私の目の中にあっても、私はそれを見ることができませんでした。
'関数内$ kontrata'、親スコープにアクセスすることはできません..あなたは、グローバルVARとして' $ kontrata'を定義する必要があり、関数内でアクセス 'グローバルの$ kontrata'、または$ kontrata'として'渡しますファンクションの引数 –