PHP range () function
Examples
Create a "0" to the element "5" between the array:
<?php
$number = range(0,5);
print_r ($number);
?>
$number = range(0,5);
print_r ($number);
?>
Running instance »
Definition and Usage
range () function creates an array that contains the specified range of elements.
This function returns an element from the low to high between the array contains.
Note: If the parameter is greater than the high low parameters, the array will be created from high to low.
grammar
range( low,high,step )
参数 | 描述 |
---|---|
low | 必需。规定数组元素的最小值。 |
high | 必需。规定数组元素的最大值。 |
step | 可选。规定元素之间的步进制。默认是 1。 |
technical details
return value: | Returns an array of elements from low to high include. |
---|---|
PHP version: | 4+ |
Update log: | step parameter was added in PHP 5.0 in. In PHP 4.1.0 to 4.3.2 version, the function of the digital string as a string instead of an integer. Numeric string will be used for character sequences, for example, "5252" is seen as "5." Support for character sequences and decrementing arrays was added in PHP 4.1.0. The character sequences are limited to a length. If the length is greater than a, only the first character. Prior to this version, range () only generated incrementing integer arrays. |
More examples
Example 1
It returns a "0" to between "50" and 10 incremental element of the array:
<?php
$number = range(0,50,10);
print_r ($number);
?>
$number = range(0,50,10);
print_r ($number);
?>
Running instance »
Example 2
Letters - Returns an element from "a" to "d" between the array contains:
<?php
$letter = range("a","d");
print_r ($letter);
?>
$letter = range("a","d");
print_r ($letter);
?>
Running instance »
Complete PHP Array Reference