range
Create an array based on range, containing specified elements
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 .
Create an array containing ranges of elements from "0" to "5":
<?php $number = range ( 0 , 5 ) ; print_r ( $number ) ; ?>
Try it yourself
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
Using letters - Return an array containing elements from "a" to "d":
<?php $letter = range ( "a" , "d" ) ; print_r ( $letter ) ; ?>
Try it yourself
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. |
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.