我在使用 PHP 构建动态网格时遇到了问题,如下所示:
我有一个包含各种尺寸图像的数组,但宽度始终为 900 或 1800。
看起来像这样:
$images = array('img_1_900.jpg', 'img_2_900.jpg', 'img_3_1800.jpg', 'and so on');
有什么聪明的方法可以做到这一点吗?我对 PHP 有点陌生,所以任何提示都很好。这是我到目前为止得到的:
$img_count = count($images);
$i = 1;
while($i <= $img_count){
list($width) = getimagesize($images[$i]);
if($width = 1800){
}
$i++;
}
我知道这没有任何作用,但我只是不知道从这里到哪里去。希望有好心人能帮我一点忙。我不能只是 float 它们,因为即使在调整大小后它们也需要保持在线,所以某种表格/表格分区必须这样做。我猜。
提前致谢!
最佳答案
如果你的图像数组总是以相同的方式构建......并且没有得到排序......
$i = 0;
$html = "<table cellpadding='0' cellspacing='10' border=1>"
foreach($image as $img){
if($i == 0)
$html .= "<tr>";
if($i < 2){
$html .= "<td><img src='{$img}' /></td>";
$i++;
}
if($i == 2){
$html .= "</tr><tr>";
$html .= "<td colspan=2><img src='{$img}' /></td>";
$i = 0;
}
}
echo $html;
关于PHP选择具有特定宽度的图像并构建网格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25363134/