Hello and welcome to our community! Is this your first visit?
Enjoy an ad free experience by logging in. Not a member yet? Register.

# Thread: How to bold specific numbers using modulos

1. ## How to bold specific numbers using modulos

Hello,

I will like to use PHP to generate the following numbers:

12345678910111213141516171819202122232425262728293031323334353637383940

And THEN bold and underline the following specific numbers like this:

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40.

Please, how would I achieve this? I used the following codes but not working:

While (\$count => 40) {
If (\$count %2 ==1)
Echo \$count;
}

Thanks and God blessed.

2. The modulo needed to target specific elements would be 10 == 0, since you want all the tens.

echo \$count % 10 == 0 ? \$count : '<b>' . \$count . '</b>', ' ';

Though I'd have to know what the data is and WHY it's getting bold or why it isn't... since data dictates what the actual markup should be. From an efficiency standpoint in terms of what's created for markup, the above is trash.

In any case, a modulo is just the remainder after a divide... so %2 means that 0 is 0, 1 is 1, 2 is 0, 3 is 1, and so forth. %10 means that you just get the final digit, 0..9 as the result...

Code:
``` 0 / 10 == 0 remainder 0,  so 0 % 10 == 0
2 / 10 == 0 remainder 2, so 2 % 10 == 2
28 / 10 == 2 remainder 8, so 28 % 10 == 8
30 / 10 == 3 remainder 0, so 30 % 10 == 0```
That's all it does, is give you the remainder... so to target all multiples of ten, you \$count % 10 == 0

Interstingly under the hood on x86 platforms the operation for divide and modulo are the same -- divide. It returns the integer result in AX and remainder in DX. This can lead to many C and other high level languages doing divide (a slow operation) multiple times when it doesn't have to.

3. Hi,

Thanks for your reply. I will go and try this and let you know if it works.

4. Hi,

It works perfectly now. Thanks you so much.

Please, how can I use for loop instead of while loop to generate the following numbers exactly:

12345678910111213141516171819202122232425262728293031323334353637383940.

I used the following codes but not working as expected:

for (\$i = 1; \$i < 40; \$++)
{
echo \$i. '<b>'<u>'.\$i. '</b>'<.u>';

Thanks.