Jess McKenzie Jess McKenzie - 2 months ago 7
PHP Question

If statement to include a third colour

In my code below I have it so that each box has a different colour

blue
or
green
.

How can I adjust the code so that I can add a third colour like
grey
?

I got the code below from one of my other SO questions that I asked and could someone also explain what the
%2
means within the
if
statement

Code:

<?php $class = 0; ?>
@foreach ($dealsDB as $deal)
<div class="col-md-4">
<div class="panel panel-default">
<div class="panel-heading @if($class%2==0) green @else blue @endif">
<h4><i class="fa fa-fw fa-gift"></i>{{ $deal->title }}</h4>
</div>
<div class="panel-body">
<p>{{ $deal->content }}</p>
</div>
</div>
</div>
<?php $class++;?>
@endforeach

Answer

never used Laravel 5 Blade

but logic suggests

 <div class="panel-heading @if($class%3==1) green @elseif($class%3==2) blue @else pink @endif">