Question: enter five numbers in the input box (the five numbers are separated by spaces). Use a one-dimensional array to compileProgramCalculate their average value (retain 2 decimal places ). You can think about how to do this on your own.
ReferenceCode:
<HTML> PHP // Receive and submit (input value) Request $ Grade = @ $ _ Request ['Grade' ]; // Echo $ grades; // split it into an array $ Grades =Explode ("", $ Grade ); // Print_r ($ grades); // defines the total number of variables $ Total = 0 ; // Calculate the total score For ( $ I = 0; $ I < Count ( $ Grades ); $ I ++){ $ Total + = $ Grades [ $ I ];} // The round function retains decimal places | this is a rounding method that retains 2 decimal places // The echo 'average is: '. Round ($ total/count ($ grades), 2 ); ?> <Form action = "array01.php" method = "Post"> Enter : <Input type = "text" name = "Grade" value = "<? PHP echo $ Grade ;?> "> <Input type =" Submit "value =" Submit "> </form> <? PHP // The number_format () function is a reserved number of digits, While formatting the number with a thousand characters Echo 'Mean :'. Number_format ( $ Total / Count ( $ Grades ), 2 ); // Echo 'average: '. Round ($ total/count ($ grades), 2 ); ?> </Body>