Php notes: php functions range () round () and list () instructions for use _ PHP Tutorial

Source: Internet
Author: User
Php notes: use of the range () round () and list () functions of php. The range () function is a simple method to quickly create an array. an integer from low to high is used to fill the array. the function returns an array containing all integers within the range. the format is as follows: arrayra

1>

The range () function is a simple method to quickly create an array. an integer from low to high is used to fill the array. the function returns an array containing all integers in the next range. the format is as follows:

Array range (int low, int high [, int step])

Typical usage:

Example: create an array of 6 numbers (DICE) from 1 to 6)

$ Die = range (0, 6 );

Create an array of all double numbers from 0 to 30

$ Even = (, 2); // the step size is 2.

This function can be used not only as a number but also as a letter.

For example

$ Words = range ('A', 'z ');

An array containing all letters A to Z will be created. this can be used to generate the verification code function.

II>

Round () function

I am afraid that this function will be confused. This function is quite different from the range () above.

This function is used

Precision of floating point number

Float round (float var [, int preisin })

Typical usage

Example: $ pi = 3.141592653;

Round ($ pi, 4 );

Echo $ pi;

Will output 3.1415

3>

List () function

The list () function can extract multiple values from a group in one operation. assign values to the variable at the same time. The form is as follows:

Void list (mixed)

Typical usage

The code is as follows:



$ Info = array ('Coffee ', 'Brown', 'Caffeine ');

// Listing all the variables
List ($ drink, $ color, $ power) = $ info;
Echo "$ drink is $ color and $ power makes it special. \ n ";

// Listing some of them
List ($ drink, $ power) = $ info;
Echo "$ drink has $ power. \ n ";

// Or let's skip to only the third one
List (, $ power) = $ info;
Echo "I need $ power! \ N ";

?>


The above example is taken from the PHP Manual You can use list () and regular expressions to cut strings and store them in the variable table. Typical usage List ($ name, $ occupation, $ color) = exolode ("|", $ line );

The wide range () function is a simple method to quickly create an array. it fills the array with an integer from low to high. the function returns an array containing all integers within the range. the format is as follows array ra...

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.