Range (incerementor?)

Hello,

I accidentally discovered this while playing around with “RANGE”.

[php]<?php
$numbers = range (1,20, 2);
sort($numbers);
for($n=0; $n<=20; $n++)
{
echo “$numbers[$n]<br >\n”;
{
?>[/php]

OUTPUT:
1
3
5
7
9
11
13
15
17
19

Whoa! Is this a standard function of “range”–the last digit /element in the “range” acts as an incrementor?
Any other neat functions with regard to this?
Or is this a fluke?

Thanks,
Chris

By the way, I mistakenly typed the last digit (2) and that’s how I came across this result.

It is the standard function of range. If you look at the page for the range function in the manual then you can see the last argument is the step:

If a step value is given, it will be used as the increment between elements in the sequence. step should be given as a positive number. If not specified, step will default to 1.

Just saw this.

Thanks, jSherz!

Sponsor our Newsletter | Privacy Policy | Terms of Service