Question: I have this php code:

```
$count = 8;

    echo '<div style="background-color:green">';

    for($i=1; $i<=$count; $i++) {
        echo $i;

        if($i%2 == 0) {
            echo '</div><div style="background-color:green">';
        }
    }

    echo '</div>';

```

What this will do is to wrap the numbers in a div with green background color every 2. I wanted to make something like in the snippet

```html
<div style="background-color:green">12</div>
<div style="background-color:yellow">34</div>
<div style="background-color:green">56</div>
<div style="background-color:yellow">78</div>
```

how can i do this in php? please help. Thanks in advance =)

Answer: 
To match your snippet, start at 12 and increment 22 on each iteration. changed to DRY for my fans.

```
<?php
$start = 12;
$end = 78;

for ($i=$start; $i<=$end; $i=$i+22) {
    echo '<div style="background-color:'.($i%4 == 0 ? 'green' : 'yellow').'">'.$i.'</div>';
}

```

Result:

```
<div style="background-color:green">12</div>
<div style="background-color:yellow">34</div>
<div style="background-color:green">56</div>
<div style="background-color:yellow">78</div>

```

You could also achieve the same with using a `foreach` with a `range()`:

```
foreach (range(12, 78, 22) as $i => $num) {
    echo '<div style="background-color:'.($i%2 == 0 ? 'green' : 'yellow').'">'.$num.'</div>';
}

```
maybe this? 

```
$count = 8;

        for($i=1; $i<=$count; $i++) {        

            if($i%2 == 0) {
                echo '</div><div style="background-color:green">'.$i;
            }else{
                echo '<div style="background-color:yellow">'.$i;
            }

            echo '</div>'
        }

```