The range function is to create an array containing elements in a specified range. The syntax for using this function is "range(low,high,step)", where the parameter low specifies the minimum value of the array, and the parameter high specifies The highest value of the array, the parameter step specifies the step system between elements.
The operating environment of this article: Windows 7 system, Dell G3 computer, PHP version 7.1.
PHP range() function is used to create an array based on a range, containing specified elements.
php range() function syntax
Function: Create an array containing elements in the specified range
Syntax:
range(low,high,step)
Parameters:
low Required. Specifies the minimum value of the array.
high Required. Specifies the maximum value of the array.
step Optional. Specifies the stepping between elements. The default is 1.
Description: This function creates an array containing integers or characters from low to high (including low and high). If high is smaller than low, return the array in reverse order.
php range() function example
<?php $number = range(1,6); print_r ($number); ?>
Output:
Array ( [0] => 1 [1] => 2 [2] => 3 [3] => 4 [4] => 5 [5] => 6 )
php range() function example
<?php $str = range('b','e'); print_r ($str); ?>
Output:
Array ( [0] => b [1] => c [2] => d [3] => e )
This article is an introduction to the PHP range function. I hope it will be helpful to friends in need!
The above is the detailed content of How to use range function. For more information, please follow other related articles on the PHP Chinese website!