How to bold and underline specifit number using FOR 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
lezy
Forum Newbie
Posts: 2
Joined: Mon Apr 18, 2016 7:14 am

How to bold and underline specifit number using FOR LOOP

Post by lezy »

FHello everyone,

Please how can I use for loop to generate the following numbers exactly:

12345678910111213141516171819202122232425262728293031323334353637383940.

I used the following codes but not working as expected:

Code: Select all

for ($i = 1; $i < 40; $++)
{
echo $i. '<b>'<u>'.$i. '</b>'<.u>';
Thanks.
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: How to bold and underline specifit number using FOR LOOP

Post by Celauran »

That's not even a complete loop. What are you actually trying to do?
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: How to bold and underline specifit number using FOR LOOP

Post by Christopher »

So something like the below will work. Since you appear to want to highlight every 10th value starting at 15, I changed the values to multiples of 10 (i.e., $i - 5) and then checked the remainder of that by dividing by 10 to see if was a multiple of 10.

Code: Select all

for ($i = 1; $i < 40; ++$i) {
	if (($i >= 15) && (($i - 5) % 10 == 0)) {
		echo "<b><u>$i</b></u> ";
	} else {
		echo "$i ";
	}
}
(#10850)
lezy
Forum Newbie
Posts: 2
Joined: Mon Apr 18, 2016 7:14 am

Re: How to bold and underline specifit number using FOR LOOP

Post by lezy »

Hi Christopher,

Thanks for your assistance.

The codes you gave did exactly what I want.

Thanks once again.
Post Reply