Computer >> Computer tutorials >  >> Programming >> PHP

range() function in PHP


The range() function creates an array containing a range of elements. It returns the elements from start to end.

Syntax

range(start, end, step)

Parameters

  • start − first value

  • end − last value

  • step − the increment in the range

Return

The range() function returns the elements from start to end.

Example

The following is an example −

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

Output

The following is the output −

Array
(
[0] => 0
[1] => 3
[2] => 6
[3] => 9
[4] => 12
)