PHP Basics Tutorial php Array exercises (2)

Source: Internet
Author: User
Tags getting started with php php basics php programming language
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!

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.