Current Location: Home> Function Categories> range

range

Create an array based on range, containing specified elements
Name:range
Category:Array
Programming Language:php
One-line Description:Creates an array containing the specified range units.

Definition and usage

range() function creates an array containing elements of the specified range.

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

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

Example

Example 1

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

 <?php
$number = range ( 0 , 5 ) ;
print_r ( $number ) ;
?>

Try it yourself

Example 2

Returns an array of elements between "0" and "50" and incremented by 10:

 <?php
$number = range ( 0 , 50 , 10 ) ;
print_r ( $number ) ;
?>

Try it yourself

Example 3

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

 <?php
$letter = range ( "a" , "d" ) ;
print_r ( $letter ) ;
?>

Try it yourself

grammar

 range ( low , high , step )
parameter describe
low Required. Specifies the lowest value of the array.
High Required. Specifies the highest value of the array.
step Optional. Specifies the stepping system between elements. The default is 1.

illustrate

This function creates an array containing integers or characters from low to high (including low and high ). If high is smaller than low , an array in reverse order is returned.

Similar Functions
Popular Articles