Consider:
<?php
class hitung
{
function hitungBiaya($arr, $totalBiaya)
{
$totalBiaya += $arr[0]['biaya'];
array_splice($arr, 0);
if ($arr !== null && count($arr) > 0) {
$this->hitungBiaya($arr, $totalBiaya);
}
return $totalBiaya;
}
}
$hitung = new hitung;
$data = [
[
"biaya" => 100,
], [
"biaya" => 1000
],
[
"biaya" => 5000
],
[
"biaya" => 3000
]
];
$jumlah = $hitung->hitungBiaya($data, 0);
echo $jumlah;
?>
How can I fix this?
I expected to get 8100, but when I run this function, it only gives me 100 as a result.