- Impact
- 0
Ok It's pretty easy to make a name list in PHP as long as you know how to use arrays and loops. Here's an example:
This displays:
Name 1 is John
Name 2 is Sarah
Name 3 is Steven
Name 4 is Brittany
Name 5 is David
On your page. You can always replace the
with what you want but leave the $namenumber and the $names[$x] alone unless you changed them to begin with. You can also replace or add more names. Just don't forget to add more to the $number. Also since we want it to be set up counting up from one, the $number will always be one greater than the amount of names shown.
PHP:
<?
$names[0] = 'John';
$names[1] = 'Sarah';
$names[2] = 'Steven';
$names[3] = 'Brittany';
$names[4] = 'David';
$number = 5;
$x = 0;
while ($x < $number) {
$namenumber = $x + 1;
echo "Name $namenumber is $names[$x]<br>";
++$x
}
?>
This displays:
Name 1 is John
Name 2 is Sarah
Name 3 is Steven
Name 4 is Brittany
Name 5 is David
On your page. You can always replace the
PHP:
"Name $namenumber is $names[$x]<br>";