Created
July 1, 2025 05:38
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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