Author Topic: Range (incerementor?)  (Read 124 times)

Chris

  • New Member
  • *
  • Posts: 14
  • Karma: +1/-0
    • View Profile
Range (incerementor?)
« on: January 27, 2012, 02:12:50 PM »
Hello,

I accidentally discovered this while playing around with "RANGE".

PHP Code: [Select]
<?php
$numbers 
range (1,202);
   
sort($numbers);
      for(
$n=0$n<=20$n++) 
     {
        echo 
"$numbers[$n]<br \>\n";
     {
?>


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


Chris

  • New Member
  • *
  • Posts: 14
  • Karma: +1/-0
    • View Profile
Re: Range (incerementor?)
« Reply #1 on: January 27, 2012, 02:14:29 PM »
By the way, I mistakenly typed the last digit (2) and that's how I came across this result.

jSherz

  • Expert PHP Helper
  • Senior Member
  • *****
  • Posts: 409
  • Karma: +4/-0
    • View Profile
    • jSherz.com
Re: Range (incerementor?)
« Reply #2 on: January 28, 2012, 08:57:29 AM »
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:

Quote
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.
Looking for PHP tutorials? View mine. Please use code or PHP tags in your posts.

Chris

  • New Member
  • *
  • Posts: 14
  • Karma: +1/-0
    • View Profile
Re: Range (incerementor?)
« Reply #3 on: February 03, 2012, 07:04:34 PM »
Just saw this.

Thanks, jSherz!