range( ) function has a third parameter that allows you specify a step amount in the range. : range « Utility Function « PHP






range( ) function has a third parameter that allows you specify a step amount in the range.

 
//array range ( mixed low, mixed high [, number step] )

<?
    $questions = range(1, 10, 2);
    // gives 1, 3, 5, 7, 9

    $questions = range(1, 10, 3)
    // gives 1, 4, 7, 10

    $questions = range(10, 100, 10);
    // gives 10, 20, 30, 40, 50, 60, 70, 80, 90, 100

    $float = range(1, 10, 1.2);
    // gives 1, 2.2, 3.4, 4.6, 5.8, 7, 8.2, 9.4
?>
  
  








Related examples in the same category

1.range( ) function creates an array of numbers between a low value and a high value.
2.If your low parameter (parameter one) is higher than your high parameter (parameter two), you get an array counting down, like this:
3.Initializing an Array As a Range or Sequence of Values: array range(mixed $start, mixed $end[, mixed $step])
4.Use range( ) to create arrays of characters, like this: