Home > Article > Backend Development > php-Arrays function-range-creates an array containing cells in a specified range_PHP tutorial
range() function
【Function】
This function will return the cells from low to high in the array,
Including themselves, if low>high, the sequence goes from high to low
【Scope of use】
>=3.0.8, php4, php5
【Use】
range(first,second,step)
first/required/specifies the minimum value of array elements
second/required/specifies the maximum value of array elements
step/optional/specifies the interval between elements/defaults to 1/this parameter was added after php5
【Example】
[php]
print_r( range( 0, 5 ) );
print_r( range( 5, 1 ) );
print_r( range( 0, 5, 2 ) );
print_r( range( 0, 5, 3) );
/*
Array
(
[0] => 0
[1] => 1
[2] => 2
[3] => 3
[4] => 4
[5] => 5
)
Array
(
[0] => 5
[1] => 4
[2] => 3
[3] => 2
[4] => 1
)
Array
(
[0] => 0
[1] => 2
[2] => 4
)
Array
(
[0] => 0
[1] => 3
)
*/
Excerpted from zuodefeng’s notes