TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 11-15-2007, 01:06 PM   #1 (permalink)
The Wanderer
 
paulOr's Avatar
 
Join Date: Nov 2007
Location: Edinburgh
Posts: 21
Thanks: 1
paulOr is on a distinguished road
Default List of numbers

im wanting to desplay a list of numbers like:
Code:
1
2
3
4
5
6
7
8
9
10
is there such code that will allow me to list numbers like this, but with my own preset bits like numbers between: 555444 - 555555 would show:
Code:
555445
555446
555447
555448
555449
555450
and so on

thanks in advance
paulOr is offline  
Reply With Quote
Old 11-15-2007, 01:16 PM   #2 (permalink)
The Reckoner
Advanced Programmer Top Contributor 
 
Karl's Avatar
 
Join Date: Sep 2007
Posts: 437
Thanks: 22
Karl is on a distinguished road
Default

Hey paulOr, try this:

PHP Code:
<?php
$aRange 
range(5554455554501);

foreach (
$aRange as $iValue)
{
    echo 
$iValue '<br />';    
}
?>
__________________
Any fool can write code that a computer can understand. Good programmers write code that humans can understand.
Karl is offline  
Reply With Quote
Old 11-15-2007, 01:19 PM   #3 (permalink)
The Wanderer
 
paulOr's Avatar
 
Join Date: Nov 2007
Location: Edinburgh
Posts: 21
Thanks: 1
paulOr is on a distinguished road
Default

perfect! <3 thanks alot
paulOr is offline  
Reply With Quote
Old 11-15-2007, 01:31 PM   #4 (permalink)
The Prestige
Upcoming Programmer Inquisitive 
 
Tanax's Avatar
 
Join Date: Sep 2007
Location: Sweden, Stockholm
Posts: 1,080
Thanks: 115
Tanax is on a distinguished road
Default

What's the arguement "1" doing??
Tanax is offline  
Reply With Quote
Old 11-15-2007, 01:43 PM   #5 (permalink)
Moderateur
RegEx Guru PHP Guru Top Contributor Advanced Programmer 
 
Salathe's Avatar
 
Join Date: Apr 2007
Posts: 1,393
Thanks: 5
Salathe is on a distinguished road
Default

The third argument to range is for the step. In other words, how much the resulting numbers should differ by. For example, range(1, 20, 3) would result in an array with values 1, 4, 7, 10, 13, 16 and 19.
Salathe is offline  
Reply With Quote
Old 11-15-2007, 01:43 PM   #6 (permalink)
La Vida es Sueño
Advanced Programmer Top Contributor 
 
Wildhoney's Avatar
 
Join Date: Sep 2007
Location: Oldham
Posts: 2,280
Thanks: 90
Wildhoney is on a distinguished road
Default

The 1 in the range specifies how much to step up by on each increment (or decrement). So if it was set to 2 then we would have:
  • 555445
  • 555447
  • 555449
  • etc...

(Salathe beat me to it but I'll keep this in anyway :)
__________________
The man who comes back through the Door in the Wall will never be quite the same as the man who went out.
Send a message via AIM to Wildhoney Send a message via MSN to Wildhoney Send a message via Yahoo to Wildhoney
Wildhoney is offline  
Reply With Quote
Old 11-15-2007, 04:03 PM   #7 (permalink)
The Prestige
Upcoming Programmer Inquisitive 
 
Tanax's Avatar
 
Join Date: Sep 2007
Location: Sweden, Stockholm
Posts: 1,080
Thanks: 115
Tanax is on a distinguished road
Default

Ahhh!
Thanks for the heads up! :D
Tanax is offline  
Reply With Quote
Old 11-15-2007, 08:55 PM   #8 (permalink)
The Acquainted
 
wGEric's Avatar
 
Join Date: Nov 2007
Posts: 166
Thanks: 0
wGEric is on a distinguished road
Default

You could do a simple for loop as well.

PHP Code:
for($i 555444$i <= 555555$i++)
{
    echo 
$i '<br />';

__________________
Eric
wGEric is offline  
Reply With Quote
Old 11-22-2007, 02:57 PM   #9 (permalink)
La Vida es Sueño
Advanced Programmer Top Contributor 
 
Wildhoney's Avatar
 
Join Date: Sep 2007
Location: Oldham
Posts: 2,280
Thanks: 90
Wildhoney is on a distinguished road
Default

I wrote a nice article about range over here. No doubt worth a read!
__________________
The man who comes back through the Door in the Wall will never be quite the same as the man who went out.
Send a message via AIM to Wildhoney Send a message via MSN to Wildhoney Send a message via Yahoo to Wildhoney
Wildhoney is offline  
Reply With Quote
Old 11-23-2007, 08:49 PM   #10 (permalink)
The Frequenter
 
ReSpawN's Avatar
 
Join Date: Nov 2007
Location: Netherlands
Posts: 460
Thanks: 49
ReSpawN is on a distinguished road
Default

Quote:
Originally Posted by wGEric View Post
You could do a simple for loop as well.

PHP Code:
for($i 555444$i <= 555555$i++)
{
    echo 
$i '<br />';

The one way, the only was, to make it easy to remember if you ask me. I am used to it since I make a lot of these loops, but you can also use while loops, instead of for and foreach. :)
Send a message via MSN to ReSpawN
ReSpawN is offline  
Reply With Quote
Old 11-25-2007, 12:44 AM   #11 (permalink)
La Vida es Sueño
Advanced Programmer Top Contributor 
 
Wildhoney's Avatar
 
Join Date: Sep 2007
Location: Oldham
Posts: 2,280
Thanks: 90
Wildhoney is on a distinguished road
Default

A similar discussion going on in another part of TalkPHP! I'd always use the for loop as well, to be fair. I don't see the range function as having any other uses apart from that which can be achieved using the for loop. I imagine the range function itself contains nothing more than a for loop.
__________________
The man who comes back through the Door in the Wall will never be quite the same as the man who went out.
Send a message via AIM to Wildhoney Send a message via MSN to Wildhoney Send a message via Yahoo to Wildhoney
Wildhoney is offline  
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


All times are GMT. The time now is 05:14 AM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design