Bài toán không chia đều column, html bằng php Full phần 2 (ok)

https://stackoverflow.com/questions/5319132/php-foreach-splitting-the-loop-into-two-parts

Ví dụ 1:

<?php
$items = array(
	array("name" => 1),
	array("name" => 2),
	array("name" => 3),
	array("name" => 4),
	array("name" => 5),
	array("name" => 6),
	array("name" => 7),
	array("name" => 8)
);
for ($i = 0; $i < 3; $i++) {
  ?>
  <li>0<?php echo $i + 1; ?><a href="#"><?php echo $items[$i]['name']; ?></a></li>
<?php
}
?>
 Logo
<?php
for ($i = 3; $i < count($items); $i++) {
  ?>
  <li>0<?php echo $i + 1; ?><a href="#"><?php echo $items[$i]['name']; ?></a></li>
<?php
}
?>

Kết quả:

Ví dụ 2:

<?php
$items = array(
	array("name" => 1),
	array("name" => 2),
	array("name" => 3),
	array("name" => 4),
	array("name" => 5),
	array("name" => 6),
	array("name" => 7),
	array("name" => 8)
);
foreach (array_slice($items, 0, 1) as $item) {
  echo sprintf("<div>%s</div>",$item["name"]);
}
echo "display logo";
foreach (array_slice($items, 1, 3) as $item) {
 	echo sprintf("<div>%s</div>",$item["name"]);
}
?>

Last updated