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

Popular posts from this blog

ubuntu - PHP script to find files of certain extensions in a directory, returns populated array when run in browser, but empty array when run from terminal -

php - How can i create a user dashboard -

javascript - How to detect toggling of the fullscreen-toolbar in jQuery Mobile? -