Home  >  Article  >  Backend Development  >  How to use the php functions range() round() and list()_PHP Tutorial

How to use the php functions range() round() and list()_PHP Tutorial

WBOY
WBOYOriginal
2016-07-20 11:17:581468browse

一>>

The range() function is a simple way to quickly create an array. Fill the array with integer values ​​from the low to high range. The function will return an array containing all integers in the range. The form is as follows

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

Typical usage is as follows

Example: Create an array of 6 numbers from 1 to 6 (dice)

$die = range(0,6);

Create an array of all even numbers from 0-30

$even = (0,20,2);//The step size is 2

This function can be used not only as numbers, but also as letters.

as

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

will create an array containing all letters from A to Z. This can be used to generate a verification code function.

二>>

round() function

This function is just for fear of confusing my memory. This function is completely different from the range() above.

What this function does is

Get the 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

三>>

list() function

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

void list(mixed)

Typical usage

复制代码 代码如下:

$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() with regular expressions to cut strings and store them in variable tables. Typical usage ​ list($name,$occupation,$color) = exolode("|",$line); <span style="line-height: 1.5; font-family: 宋体, Verdana, Arial, Helvetica, sans-serif; "><strong><br> </strong></span>

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/371927.htmlTechArticleThe range() function is a simple way to quickly create an array, filling the array with integer values ​​ranging from low to high, function Will return an array containing all integers in the sub-range. The form is array ra...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn