L
L
Lam Besis2018-04-18 12:42:06
PHP
Lam Besis, 2018-04-18 12:42:06

Set up the output of list items in 3 pieces?

There is a task: if the list has more than 3 items, add another list. Now the items are simply displayed all together, tell me how to implement it? js/php doesn't matter.

<ul class="service_list">
   <?php foreach($service_list as $row => $list_items): ?>
   <li><?php echo $list_items['item']; ?></li>
   <?php endforeach; ?>
</ul>

Answer the question

In order to leave comments, you need to log in

2 answer(s)
T
twobomb, 2018-04-18
@lambesis

<?PHP
$tmp = array_chunk($service_list,3);
foreach($tmp as $k => $v){
  echo '<ul class="service_list">';
 foreach($v as $row => $list_items)
   echo "<li>$list_items[item] </li>";
  echo '</ul>';
}
?>

U
uadeveloper, 2018-04-18
@uadeveloper

array_chunk

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question