Create array range

Creates a array with an range from, to

function array_range($from, $to, $step=1){
    $array = array();
    for ($x=$from; $x <= $to; $x += $step){
        $array[] = $x;
    return $array;
print_r(array_range(0, 20, 5));
    [0] => 0
    [1] => 5
    [2] => 10
    [3] => 15
    [4] => 20
Snippet Details

Sorry folks, comments have been deactivated for now due to the large amount of spam.

Please try to post your questions or problems on a related programming board, a suitable mailing list, a programming chat-room,
or use a QA website like stackoverflow because I'm usually too busy to answer any mails related
to my code snippets. Therefore please just mail me if you found a serious bug... Thank you!

Older comments:

Adam Moro June 03, 2008 at 07:27
Hey thanks a lot for this. It's exactly what I was looking for. The range function in PHP is great but it couldn't do what I used your function to accomplish. Thanks again!
Karl Groves February 07, 2008 at 16:26
PHP already has a function for this. It is called 'range'