Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

PHP range() Function

PHP range() Function

PHP Array ReferenceComplete PHP Array Reference Manual

Example

Create an array containing elements from "0" to "5":

Run Example »


Definition and Usage

The range() function creates an array containing elements within a specified range.

This function returns an array containing elements from low to high.

**Note:** If the low parameter is greater than the high parameter, the created array will run from high to low.


Syntax

range(

low,high,step

)

Parameters Description
low Required. Specifies the minimum value of the array elements.
high Required. Specifies the maximum value of the array elements.
step Optional. Specifies the step between elements. Default is 1.

Technical Details

Return Value: Returns an array containing elements from low to high .
PHP Version: 4+
Changelog: step This parameter was added in PHP 5.0.
 在 PHP 4.1.0 到 4.3.2 版本中,该函数将数字字符串看作字符串而不是整数。数字字符串将被用于字符序列,例如,"5252" 被看作 "5"。       
   
 支持字符序列和递减数组是在 PHP 4.1.0 中新增的。字符序列的值被限制在一个长度。如果长度大于一个,只使用第一个字符。在该版本之前,range() 只生成递增的整数数组。 |

More examples

Example 1

Return an array containing elements from "0" to "50" in increments of 10:

Run Example »

Example 2

Using letters - Return an array containing elements from "a" to "d":

Run Example »


PHP Array ReferenceComplete PHP Array Reference Manual