嗨我从控制器返回了2个数组。
$顺序
array (size=2)
0 =>
array (size=2)
'orderid' => int 1
'ostatus' => string 'Placed' (length=6)
1 =>
array (size=2)
'orderid' => int 4
'ostatus' => string 'Placed' (length=6)
$ ORDERDETAILS
array (size=2)
1 =>
array (size=3)
0 =>
array (size=3)
'oid' => int 1
'img6_path' => string 'images/product-list/pro1-list.jpg' (length=33)
'brand_name' => string 'Puma' (length=4)
1 =>
array (size=3)
'oid' => int 1
'img6_path' => string 'images/product-list/pro2-list.jpg' (length=33)
'brand_name' => string 'DressBerry' (length=10)
2 =>
array (size=3)
'oid' => int 1
'img6_path' => string 'images/product-list/pro3-list.jpg' (length=33)
'brand_name' => string 'United Colors of Benetton' (length=25)
4 =>
array (size=1)
0 =>
array (size=2)
'oid' => int 4
'img6_path' => string 'images/product-list/pro4-list.jpg' (length=33)
'brand_name' => string 'Puma' (length=4)
我正在尝试按此顺序打印:
这就是我一直在做的事情:
foreach($order as $ord)
//printing order id
foreach($orderdetail as $od)
foreach($od as $x)
//printing the products
endforeach()
endforeach()
endforeach()
但这是打印
任何人都可以告诉我如何循环播放数组,以便在按顺序打印前3个产品后,循环中断,然后按顺序打印1个产品(如上图所示)。谢谢
答案 0 :(得分:1)
@foreach($order as $ord)
//printing order id
@foreach($orderdetail[$ord->orderid] as $od)
@foreach($od as $x)
//printing the products
@endforeach
@endforeach
@endforeach
其中@foreach($orderdetail[$ord->orderid] as $od)
是一个很大的变化......我会尝试一下......