@php $count = 1 ; @endphp
@for($i = 0; $i <= 99; $i++)
@php
if($count % 6 == 0){
$css = 'honeydew';
}else{
$css = 'aliceblue';
}
$count++;
@endphp
<tr class="allrow {{$css}}" id="row_{{$i}}">
<td width="20%">
<select class="form-control select2 firstname v1" id="name1_{{$i}}" name="name[]" style="width: 100%;">
</select></td>
<td width="20%"><input type="number" name="winlose[]" id="amt1_{{$i}}" class="form-control first" value="0.00"></td>
{{-- <td width="20%"><select class="form-control select2 secondname v1" id="name2_{{$key}}" name="name2[]"></select></td>
<td width="20%"><input type="number" name="winlose[]" id="amt2_{{$key}}" class="form-control second"></td> --}}
<td width="20%"><a href="#" class="btn btn-danger remove">-</a></td>
</tr>
@endfor
Question: Trying to give 2 different colors which are honeydew and aliceblue for every 5 rows in the loop in PHP, How can I implement it? For example, the first 5 rows will be honeydew, then 5-10 rows will be aliceblue. It will respectively.
By setting the $css value and changing it every 5 records:
@php $count = 1; $css = 'honeydew'; @endphp
@for($i = 0; $i <= 99; $i++)
@php
if($count % 6 == 0){
$css = ($css === 'honeydew' ) ? 'aliceblue' : 'honeydew';
}
$count++;
@endphp
<tr class="allrow {{$css}}" id="row_{{$i}}">
<td width="20%">
<select class="form-control select2 firstname v1" id="name1_{{$i}}" name="name[]" style="width: 100%;">
</select></td>
<td width="20%"><input type="number" name="winlose[]" id="amt1_{{$i}}" class="form-control first" value="0.00"></td>
{{-- <td width="20%"><select class="form-control select2 secondname v1" id="name2_{{$key}}" name="name2[]"></select></td>
<td width="20%"><input type="number" name="winlose[]" id="amt2_{{$key}}" class="form-control second"></td> --}}
<td width="20%"><a href="#" class="btn btn-danger remove">-</a></td>
</tr>
@endfor
Here's a basic example in PHP using regex. Basically, it will check if the number ends with 0-4 and set CSS to honeydew, if not set to aliceblue.
for ($i = 0; $i <= 99; $i++) {
if (preg_match('/[0-4]$/', $i)) {
$css = 'honeydew';
} else {
$css = 'aliceblue';
}
echo $css . PHP_EOL;
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.