php - How can I skip the first if statement occuring in a loop? -
i have made loop print table <tr>
, <td>
here code:
echo "<tr>"; for($i = 0; $i < (int)count($fieldvalues); $i++){ echo "<td>" . $fieldvalues[$i] . "</td>"; if($i % 4 == 0){ echo "<td><input type='text'></td><td><input type='submit' value='add cart'></td></form></tr>"; } }
i want skip first if
statement in loop because condition $i % 4== 0
true when $i 0, is, 0 % 4 == 0
.the value of $fieldvalues
8. other method overcome appreciated.
check not 0
in conditional.
if(!empty($i) && $i % 4 == 0){
or
if($i != 0 && $i % 4 == 0){
i'd use foreach
rather for
.
a demo: https://3v4l.org/bg2ns
Comments
Post a Comment