Instructions for the php functions range of round of and list of

  • 2020-06-01 08:44:18
  • OfStack

1 > >

The range() function is a simple way to quickly create an array by populating the array with integer values in the low to high range. The function returns an array containing all integers in the subrange

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);

Creates an array of all the even Numbers from 0 to 30

,20,2 $even = (0); // step length is 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 the letters from A to Z is created. This can be used to generate captcha functions.

2 > >

round () function

In case I'm confused, this function is a far cry from range() above.

What this function does is

The precision of a floating point number

float round(float var[,int preisin})

Typical usage

Example: $pi = 3.141592653;


echo $pi;

The output of 3.1415

3 > >

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


$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 can be used with list() to cut the string into the variable scale typical use list($name,$occupation,$color) = exolode("|",$line);

Related articles: