If this is a over discussed question, forgive me. I started my self-study php 10 days ago and I have to do one exercise. I 've read related articles through several sources also incl php manual. I don't have too much programming knowledge, so what I did is somehow not so good. Anyway I write here because I hope that somebody could explain me what mistake I made, how should it be done. So tks in advance. The exercise is :
Complete the below PHP script so that it prints the sum and average of given points. The points are sent to the script as a character string, where points are separated with comma (e.g. 4,5,2). Points are divided into an array with the explode-function. The purpose of the script is to print the points separated with a space. Write only the missing statements, don’t write the whole program in the text box. Incomplete program:
$numberstring = $_GET['numberstring'];
$numberarray = explode(',',$numberstring);
// Your code here
echo "Points were: $points\n";
echo "Sum of points: $sum\n";
echo "Average of points: $average";
?>
Example output
Points were: 3 6 7 -2 0
Sum of points: 14
Average of points: 2.8
And here in below is what I tried:
<html>
<head>
<title>Online PHP Script Execution</title>
</head>
<body>
<?php
$numberstring = $_GET['numberstring'];
$numberarray = explode(',',$numberstring);
for ($i=0; $i<=$numberarray.length;$i++)
echo "points were:" ;
{ $points=$numberarray[$i];
$sum=$points+$sum;
echo $points;
};
echo "Sum of points: $sum\n";
while ($i!=0)
{$average=$sum/$i;
}
echo "Average of points: $average";
?>
</body>
</html>