Reputation: 33
My current code:
<td>
<?php echo $row['feild1'] + $row['feild2'] + $row['feild3'] + $row['feild4'] + $row['feild5'] + $row['feild6'] + $row['feild7'] + $row['feild8'] + $row['feild9'] + $row['feild10'] + $row['feild11'] + $row['feild12'] + $row['feild13'] + $row['feild14'] / 42; ?>
</td>
I'm trying to produce a percentage but it just seems to add the values together.
Upvotes: 0
Views: 177
Reputation: 80639
If all the values in array are numbers (integers or floats); you can use the array_sum
:
<?php echo array_sum($row) / 42; ?>
or maybe
<?php echo array_sum($row) / (count($row) * 4); ?>
Upvotes: 1
Reputation: 508
<td><?php echo ($row['feild1'] + $row['feild2'] + $row['feild3'] + $row['feild4'] + $row['feild5'] + $row['feild6'] + $row['feild7'] + $row['feild8'] + $row['feild9'] + $row['feild10'] + $row['feild11'] + $row['feild12'] + $row['feild13'] + $row['feild14']) / 42; ?></td>
Like so.
Also you misspelled field
. Not feild
.
Upvotes: 4