0
我必須製作一個可以通過變量($ cols)設置的列數量,每個單元格包含通過GLOB數組獲取的圖片。我現在的代碼將輸出一個正確數量的單元格和列的表格,但我需要幫助讓每張圖片都顯示出來。如何使這個可變大小的表格從GLOB數組輸出圖像?
<?php
$cols = 4;
$array = glob("include/*.{jpg}", GLOB_BRACE);
$output = "<table>\n";
$cell_count = 1;
for ($i = 0; $i < count($array); $i++) {
if ($cell_count == 1) {
$output .= "<tr>\n";
}
$output .= "<td><img src=$array></td>\n";
$cell_count++;
if ($cell_count > $cols || $i == (count($array) - 1)) {
$output .= "</tr>\n";
$cell_count = 1;
}
}
$output .= "</table>\n";
echo "$output";
?>
哇,我不能相信我錯過了。謝謝! – user2359675 2013-05-07 20:09:32