i want to sum for some data which come from function foreach in PHP, but i found error while run it, here my simple code :
<?php
$no=1;
foreach($data_tersimpan->result_array() as $dp)
{
?>
<?php
$total = 0;
$total += count($dp['id_plan']);
echo $total;
?>
<?php
$no++;
}
?>
from my code above, i print $total, then data shown like this :
1 1 1 1 1
I want to get summary 5 if i print $total
is there any suggestion to make summary in php scrypt(not in sql query)?
THanks
totalto be 5, or you want a separate variable (summary) to be 5?$totalto be 5foreach$total = 0;before the loop, your resetting it each time to 0$total = 0;out side of foreach andecho $total;after closing foreach you get count of total