This section is about the practice of PHP arrays, using a one-dimensional array averaging example, for everyone to learn the reference. Requirements: Enter 5 numbers in the input box (enter those 5 numbers separated by a space), use a one-dimensional array to write a program to find their average value (keep 2 decimal digits). Review: PHP basic tutorial PHP array exercise Code is as follows:
Please enter 5 numbers and separate them with a space _bbs.it-home.org !--? php/** * PHP Array exercises *///Connect Submit (input value) REQUEST $grade =@$_request[' grade ']; Echo $grades; Split into arrays $grades = Explode ("", $grade); Print_r ($grades); Defines the total number of variables stored $total = 0; Calculates the total score for ($i =0; $i
the!--? php//number_format () function is a reserved number of digits, while formatting the number plus the thousand character echo ' average is: '. Number_format ($total/count ($grades), 2); Echo ' averages are: '. Round ($total/count ($grades), 2);? -->
Thank you for your interest in getting started with PHP, this series of basic PHP tutorials will help PHP novice friends, quickly grasp the PHP programming language. The programmer's home will continue to introduce PHP-related tutorials For everyone, I wish you all the progress of learning! |