Home >Backend Development >PHP Tutorial >How to use the php functions range() round() and list()_PHP Tutorial
一>>
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"; ?> |
<span style="line-height: 1.5; font-family: 宋体, Verdana, Arial, Helvetica, sans-serif; "><strong><br>
</strong></span>