Neil_Bradley
asked on
array_sum
Hopefully a simple one..
How do I calculate the sum of $value?
foreach($mark as $ExamNo => $value) {
if($value != "") {
echo '<li>'.$ExamNo.' = '.$value.'</li>';
echo "the sum of $value"
}
}
Thanks,
N
How do I calculate the sum of $value?
foreach($mark as $ExamNo => $value) {
if($value != "") {
echo '<li>'.$ExamNo.' = '.$value.'</li>';
echo "the sum of $value"
}
}
Thanks,
N
ASKER
No, I specifically need the sum of the $value inside the array
"I specifically need the sum of the $value inside the array"
I don't undertand what you mean by this. Do you mean
I don't undertand what you mean by this. Do you mean
$sum_value = 0;
foreach($mark as $ExamNo => $value) {
if($value != "") {
echo '<li>'.$ExamNo.' = '.$value.'</li>';
$sum_value += $value;
echo "the sum of $sum_value"
}
}
ASKER
I have mocked up what I am trying to achieve here: http://www.statusconsultinglimited.com/questions.html
This should explain the aim of my question..
<?php
$mark = $_POST["mark"];
foreach($mark as $ExamNo => $value) {
if($value != "") {
echo '<li>'.$ExamNo.' = '.$value.'</li>';
}
}
echo"<br/>
You score was";
?>
This should explain the aim of my question..
<?php
$mark = $_POST["mark"];
foreach($mark as $ExamNo => $value) {
if($value != "") {
echo '<li>'.$ExamNo.' = '.$value.'</li>';
}
}
echo"<br/>
You score was";
?>
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Ray, as always you hit the nail on the head.
Thanks,
N
Thanks,
N
ASKER
Thanks for that..
Cheers,
N
Cheers,
N
$totalMark = array_sum( $mark );
should do it. See http://www.php.net/array_sum