1

Temat: PHP - obliczanie średniej

<?php
  if (!empty($_POST['oceny']))
      $w = $_POST['oceny']; else $w = "";
?>
<form action="" method="post">
  Podaj oceny: <input type="text" name="oceny" value="<?php echo $w; ?>">
  <input type="submit" value="Średnia">
</form>
<hr>
<?php
  if (!empty($_POST))
  {
    $oceny = $_POST['oceny'];
    $ile = strlen($oceny);
    $suma = 0;
    //
    for ($i=0; $i<=$ile-1; $i++)
    {
      $suma+=(int)$oceny[$i];
    }
    print($suma/$ile);
  }
?>