Saturday, 7 September 2013

add numbers in an array with PHP

add numbers in an array with PHP

I want all of the elements in the array to be added together, but this
doesn't seem to be working.
<?php
function mimic_array_sum($array) {
foreach($array as $total) {
$total = $total + $total;
}
return $total;
}
$var = array(1,2,3,4,5);
$total = mimic_array_sum($var);
echo $total;
?>

No comments:

Post a Comment