Need to generate numbers 1-1000000 in a list

coxi999

Junior Member
Joined
Aug 14, 2007
Messages
170
Reaction score
53
I need to generate numbers 1 - 1000000 in a list format

1
2
3
4
5
6
etc

I found this php code to do something similar but it puts the numbers like this

1,2,3,4,5,6,7,etc

Code:
<?php
 $lowestnum = 1;
 $highestnum = 1000000;
 
for($i=$lowestnum; $i<=$highestnum; $i++){
 echo "$i, ";
 }
 ?>

Could someone please give edit this code for me to put the numbers in list format. Usless at PHP :)
 
PHP:
<?php
 $lowestnum = 1;
 $highestnum = 1000000;
 
for($i=$lowestnum; $i<=$highestnum; $i++){
 echo "$i<br />";
 }
 ?>

Just replaced the ', ' with '<br />' which is the HTML for a linebreak. Enjoy
 
arr right, that simpe great, thanks alot..
 
Is it possible to edit this code so i can add a prefix to each number?

number1
number2
number3
etc?????
 
Replace $i with your prefix + $i.
So: number$i would produce number1, etc.
 
Cleaner: edit the value of $prefix

PHP:
<?php
 $prefix = 'my prefix ';
 $lowestnum = 1;
 $highestnum = 1000000;
 
for($i=$lowestnum; $i<=$highestnum; $i++){
    echo "$prefix$i<br />";
}
?>
 
You can output anything you want. Echo is just that, it displays to the browser what you "ECHO". Anything with a Dollar sign ($) in front of it is a variable.
PHP:
<?php echo "Hello World"; ?>
would display hello world... etc.
PHP:
<?php 
 $prefix = 'my prefix ';
 $postfix = '<br />';
 $lowestnum = 1; 
 $highestnum = 1000000; 
  
for($i=$lowestnum; $i<=$highestnum; $i++){ 
    echo $prefix.$i.$postfix; 
} 
?>
is how I'd do it
PHP:
http://php.net/echo
 
Back
Top