使用laravel根据订单号对图像进行排序

时间:2017-11-10 07:48:15

标签: php html image laravel sorting

我有5张图片。我需要根据订单显示图像。

现在我有数组中的顺序,如

2,3,5,1,4

现在我的图片位于$new->image1,$new->image2,$new->image3,$new->image4,$new->image5

我的结果应该像订单如上所述,

顺序就像$new->image2,$new->image3,$new->image5,$new->image5,$new->image1,$new->image4

我怎样才能实现这个目标

<table style="text-align:justify" align="center" border="1" cellspacing="0" >
     {{$new->img_order}}
     <?php 
      $order_array = explode(",", $new->img_order);
      $img1 = $new->image2;
      dd($new->image2);
     ?>
            <tr>
              <td height="600" rowspan="3"><img width="350" height="910px" src="{{asset('collage/'.$new->image1)}}" class="img-responsive" alt=""></td>
              <td height="300" colspan="2"><img width="500" height="300px" src="{{asset('collage/'.$new->image2)}}" class="img-responsive" alt=""></td>
            </tr>
            <tr>
              <td width="250" ><img width="250" height="350px" src="{{asset('collage/'.$new->image3)}}" class="img-responsive" alt=""></td>
              <td width="250"><img width="250" height="350px" src="{{asset('collage/'.$new->image4)}}" class="img-responsive" alt=""></td>
            </tr>
            <tr>
              <td colspan="2"><img width="500" height="250px" src="{{asset('collage/'.$new->image5)}}" class="img-responsive" alt=""></td>
            </tr>
          </table>

1 个答案:

答案 0 :(得分:3)

我只是想知道你为什么不在数组中保存图像路径,但是有很多image1, image2, ....

如果不对图像进行排序,您可以使用

按顺序数组回显图像
$new->{'image' . $order[0]}
$new->{'image' . $order[1]}
$new->{'image' . $order[2]}
...