3 回答
TA贡献1828条经验 获得超3个赞
您不能在数组语法中使用循环。解决的办法是在外面构建数组,然后作为参数传递。我不确定您正在寻找的确切结构,但类似于这样:
$data = [];
for ($z = 0; $z < 8; $z++) {
$data[] = ($masterCategoryList[$z]['name'] . $productMatchesToMasterCategory);
}
return view('shop.landing', [
'productMatchesToMasterCategory' => $data,
'tomorrow' => Carbon::tomorrow(),
]);
TA贡献1829条经验 获得超13个赞
您应该在返回视图之前执行此操作:
$productMatchesToMasterCategoryArray = [];
for($z = 0; $z < 8; $z++) {
$productMatchesToMasterCategoryArray[] = ($masterCategoryList[$z]['name'].$productMatchesToMasterCategory);
}
return view('shop.landing', [
'productMatchesToMasterCategory' => $productMatchesToMasterCategoryArray
//Other variables here
]);
希望能帮助到你。
TA贡献1852条经验 获得超1个赞
您可以尝试在返回视图之前获取随机 8 个元素的数组。
$productMatchesToMasterCategoryArray = [];
foreach($masterCategoryList as $z){
$productMatchesToMasterCategoryArray[] = ($z['name'].$productMatchesToMasterCategory);
}
$random_Array=array_rand($productMatchesToMasterCategoryArray,8);
return view('shop.landing', [
'productMatchesToMasterCategory' => $random_Array,
'tomorrow' => Carbon::tomorrow(),
]);
- 3 回答
- 0 关注
- 271 浏览
添加回答
举报
