php - loop and split to display by 2 rows or divs -


currently , did :

<?php  $a = array(1,2,3,4,5,6); echo "<div>"; for($i=1;$i<=3;$i++){     echo $i; } echo "</div>";  echo "<div>"; for($i=4;$i<=6;$i++){     echo $i; } echo "</div>"; ?> 

how can use 1 loop , produce same output (display 2 rows 3 cols)?

you can try using array_chunk(). example:

$a = array(1,2,3,4,5,6); $a = array_chunk($a, 3); echo '<div>'; foreach($a $v){     echo $v[0] . $v[1] . $v[2];     echo '<br />'; } echo '</div>'; 

Comments

Popular posts from this blog

c++ - QTextObjectInterface with Qml TextEdit (QQuickTextEdit) -

javascript - angular ng-required radio button not toggling required off in firefox 33, OK in chrome -

xcode - Swift Playground - Files are not readable -