Number Loops

Hi all,

I hope somebody can shed some light on a PHP program I’m trying to run related to loops.

I have created a 1 - 10 loop as >> for ($x=0; $x<=10; $x++)
{
echo " $x
";
}

but now I want to modify it so that each number that is divisible
by two is bold??

Regards,

James.

[php]<?php
for ($x = 0; $x <= 10; $x++)
{
if ($x % 2 == 0)
echo “even”;
else
echo “odd”;
}
?>[/php]

Boom. Note that using this, you most likely want to start with $x = 1. This is commonly used to break rows (e.g. 2 columns per row). If you don’t start with 1, it will not break properly.

Thanks for the help on this question!! much appreciated.

Sponsor our Newsletter | Privacy Policy | Terms of Service