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: 
You could achieve that effect doing something like this:

```
<?php   
    $count          = 8;
    $colorMatrix    = ['odd'=>'green', 'even'=>'yellow'];

    for($i=1; $i<=$count; $i++) {
        $oddEven    = ($i%2) ? "odd" : "even";
        echo "<div style='background-color:{$colorMatrix[$oddEven]}'>{$i}</div>";   
    }

```

Or even much simpler and straightforward:

```
    $count          = 8;        
    for($i=1; $i<=$count; $i++) {
        $oddEven    = ($i%2) ? "green" : "yellow";
        echo "<div style='background-color:{$oddEven}'>{$i}</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>'
        }

```