How to display two diferent text styles by Loop

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
yosuke_
Forum Commoner
Posts: 64
Joined: Tue Apr 13, 2004 12:29 pm

How to display two diferent text styles by Loop

Post by yosuke_ »

Hi!
I know topic name sounds stupid, but how can I display something like this:
0
1
2
3
4

Here is my code:

Code: Select all

<?php
for($i=0;$i<10;$i++){
$x = 0;
if($x == 0){
echo "$i<br>";
$x++;
}
else 
{
echo "<b>$i</b><br>";
$x--;
}
}
?>
This is the result:
0
1
2
3
4
This is the result I need:
0
1
2
3
4
Please help me! Thank you!
kettle_drum
DevNet Resident
Posts: 1150
Joined: Sun Jul 20, 2003 9:25 pm
Location: West Yorkshire, England

Post by kettle_drum »

Code: Select all

for($x=0;$x<5;$x++){
   if($x%2){
      echo "<b>$x</b><br />";
   }else{
      echo $x."<br />";
   }
}
User avatar
launchcode
Forum Contributor
Posts: 401
Joined: Tue May 11, 2004 7:32 pm
Location: UK
Contact:

Post by launchcode »

Code: Select all

<?php
	$bold = true;
	for ($i = 0; $i < 20; $i++)
	{
		if ($bold)
		{
			echo "<b>$i</b><br>";
			$bold = false;
		}
		else
		{
			echo "$i<br>";
			$bold = true;
		}
	}
?>
yosuke_
Forum Commoner
Posts: 64
Joined: Tue Apr 13, 2004 12:29 pm

Post by yosuke_ »

Thank you bouth very much!!! :wink:
Post Reply