Skip to content

Instantly share code, notes, and snippets.

@stnc
Created July 1, 2025 05:38
Show Gist options
  • Save stnc/f61559de995ba7aa74472f753a54d318 to your computer and use it in GitHub Desktop.
Save stnc/f61559de995ba7aa74472f753a54d318 to your computer and use it in GitHub Desktop.
php array_chunk — Split an array into chunks / used array chunk with html table
<table>
<colgroup>
<col width="50">
<col width="50">
<col width="50">
<col width="50">
</colgroup>
<tbody>
<?php
$colors = array("red1", "green1", "blue1", "yellow1","red2", "green2", "blue2", "yellow2", "red3", "green3", "blue3", "yellow3", "red4", "green4");
echo count($colors) . "<br>";
// 4 elemanlı gruplara ayır
$gruplar = array_chunk($colors, 4);
// Grupları yazdır
foreach ($gruplar as $index => $grup) {
echo "<tr>";
foreach ($grup as $index2 => $val) {
echo " <td>$val </td> ";
}
echo "</tr>";
}
?>
</tbody>
</table>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment