I want to divide the values of an array which is formated:
[0] => value0 [1] => value1 [2] => value2 [3] => value3 [4] => value4 etc.
into different tables so that printing the array would be more compact.
My code first checks for an array and then sorts it, removes values ".." and "." and then divides it 4 portions which are then foreached and printed. However for some reason a part of the array values doesn't always get printed. Is there a better way to do this or to fix the bug?
Thanks a bunch! 🙂
if(is_array($entries)){
natsort ($entries);
array_reverse($entries);
$entries = preg_replace('/^\.$/', '', $entries);
$entries = preg_replace('/^\.\.$/', '', $entries);
$amount = count($entries);
$entries1 = array_slice($entries, 0, ($amount/4));
$entries2 = array_slice($entries, ($amount/4)+1, ($amount/4));
$entries3 = array_slice($entries, ($amount/2)+1, ($amount/4));
$entries4 = array_slice($entries, ($amount/2+$amount/4));
echo "<table>";
echo "<tr valign=\"bottom\"><td>";
echo "<table width=\"150\" border=\"0\" bordercolor=\"#000000\">";
echo "<tr><td align=\"center\"><b>Array values</b></td></tr>";
foreach($entries1 as $entry_file){
$entryprint = "<tr><td align=\"center\">$entry_file</td></tr>";
echo "$entryprint";
}
echo "</table>";
echo "</td><td>";
echo "<table width=\"150\" border=\"0\" bordercolor=\"#000000\">";
foreach($entries2 as $entry_file){
$entryprint = "<tr><td align=\"center\">$entry_file</td></tr>";
echo "$entryprint";
}
echo "</table>";
echo "</td><td>";
echo "<table width=\"150\" border=\"0\" bordercolor=\"#000000\">";
foreach($entries3 as $entry_file){
$entryprint = "<tr><td align=\"center\">$entry_file</td></tr>";
echo "$entryprint";
}
echo "</table>";
echo "</td><td>";
echo "<table width=\"150\" border=\"0\" bordercolor=\"#000000\">";
foreach($entries4 as $entry_file){
$entryprint = "<tr><td align=\"center\">$entry_file</td></tr>";
echo "$entryprint";
}
echo "</table>";
echo "</td></tr></table>";
} else {
echo "Not array";
}