PHP Notes: Php function range () round () and list () use Instructions _php instance

Source: Internet
Author: User

A >>

The range () function quickly creates an array of simple methods that populate the array with an integer value of low to high range, and the function returns an array containing all the integers in the secondary range. The form is as follows

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

Typical usage is as follows

Example: Set up 1-6 of 6-digit arrays (DICE)

$die = range (0,6);

Set up 0-30 arrays of all numbers

$even = (0,20,2);//Step 2

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

Such as

$words = Range (' A ', ' Z ');

An array of all letters from A to Z will be created. This can be used to generate a validation code function.

b >>

Round () function

This function is afraid I'm confused. This function is different from which range () above.

The role of this function is to

The precision of the floating-point number

Float round (float var[,int preisin})

Typical usage

Example: $pi = 3.141592653;

Round ($PI, 4);

Echo $pi;

Will output 3.1415

Three >>

List () function

The list () function can extract multiple values from an array in one operation. Assign values to variables at the same time. The form is as follows

void list (mixed)

Typical usage

)
Copy Code code as follows:

<?php

$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 the third one
list (,, $power) = $info;
echo "I need $power!\n";

?>

(
上例摘自PHP手册
可以用list()配合正则来切割字符串存入变量表
典型用法
list($name,$occupation,$color) = exolode("|",$line); 

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.