Question: I have an array of numbers, for example (calendar days):
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

I want to highlight every three numbers after two.

So it should looks like: **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**

Or it can be two after two, or four after two or any other pair.

I need some algorithm to make this work, help please.

Answer: 
You can use modulo `%`. If modulo is less than or equal to 2 (0,1,2) highlight it.

```
$arr = array(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);

    foreach( $arr as $key => $value ) {
        if ( ( $key % 5 ) <= 2 ) echo "<b>" . $value  . "</b>"; 
        else echo $value; 

        echo "<br />";
    }

```
You can achieve this with a simple `mod` on `$i` in a for loop:

```
for ($i = 0; $i < 31; $i++) {
    if ($i%5 == 1 || $i%5 == 2 || $i%5 == 3 ) {
        echo "<strong>" . $i . "</strong>";
    } else {
        echo $i;
    }
}

```

It will need slight adjustments to output how you need it output, but the general logic should work.

Check here for a working example <https://ideone.com/bpgdgm>