I'm having trouble with building a dynamic grid with PHP like this:

我在使用PHP构建动态网格时遇到了麻烦:

I have an array containing images in various sizes, but always either 900 or 1800 in width.

我有一个包含各种尺寸图像的数组,但宽度始终为900或1800。

Looks like this:

看起来像这样:

$images = array('img_1_900.jpg', 'img_2_900.jpg', 'img_3_1800.jpg', 'and so on');

Is there any smart way to do this? I'm kind of new to the PHP-thing, so any hints could be nice. Here's what i got so far:

有没有聪明的方法来做到这一点?我是PHP的新手,所以任何提示都可能很好。这是我到目前为止所得到的:

 $img_count = count($images);
 $i = 1;
 while($i <= $img_count){
    list($width) = getimagesize($images[$i]);
    if($width = 1800){

    }
    $i++;
 }

I know this does nothing, but i simply don't know where to go from here. Hope some kind soul could help me a little along. I can't just float them, because they need to stay on line even after a resize, so some kind of table/table-div has to do it. I guess.

我知道这没什么,但我根本不知道从哪里开始。希望一些善良的灵魂可以帮助我一点点。我不能只是浮动它们,因为即使在调整大小之后它们也需要保持在线,因此某种表/ table-div必须这样做。我猜。

Thanks in advance!

提前致谢!

2 个解决方案

#1


0

if your image array is allway build in the same way... and not getting sorted...

如果你的图像数组是以相同的方式构建的...而不是排序......

$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;

更多相关文章

  1. 从数组中构建越来越长的字符串
  2. 如何在应用程序中嵌入图像并在HTML控件中使用它们?
  3. 指导我优化我的PHP代码,用数组中的空数据填充缺失值
  4. 在数组中找到键是找不到文本[重复]
  5. 为什么foreach在循环中不修改数组时要复制数组?(复制)
  6. 如何将项添加到json文件格式化数组
  7. 从数组php获得第一个非空值。
  8. 迭代XML元素并将元素推送到数组中
  9. 学习成绩统计-【数组操作】

随机推荐

  1. Android的路接下来该怎么走?
  2. android sqlite 操作 说明 记录
  3. android设置背景
  4. Android上的滤镜效果
  5. cocos2dx android
  6. Android函数重构(MVC)
  7. Android Service创建USB HOST通信
  8. Android(安卓)ApiDemos示例解析(117):Vie
  9. Android进阶知识树——Android系统的启动
  10. Android KitKat 4.4 Wifi移植之AP模式与