laravel - 如何在 for 和 if 语句中使用动态数组索引,因为我在 laravel Blade 中得到了 Undefined offset: 1
问题描述
我是 laravel 的新手,当我想使用变量访问数组时,我遇到了 Undefined offset: 1 错误。
如何在 for 和 if 语句中使用索引?
这是我的代码。
@for($i = 0; $i< count($type['layout']); $i++)
@if($type['layout']['col'] == 1)
@if($type['layout']['properties'][$i]['type'] == "text")
text input
@else if($type['layout']['properties'][0]['type'] == "radio")
radio btn
@endif
@endif
@endfor
数组格式在这里
array:1 [▼
"layout" => array:2 [▼
"col" => "1"
"properties" => array:1 [▼
0 => array:3 [▼
"type" => "text"
"label" => "username"
"text" => "Enter your username"
]
]
]
]
解决方案
推荐阅读
- javascript - JavaScript 加载资源失败:找不到文件,但该文件是 Laravel 自动生成的视图
- java - 如何在 Java 中为 0MQ ( ZeroMQ ) 设置超时?
- java - 如何以编程方式创建 kerberos 凭据缓存?
- sql - postgresql中的数据透视表
- html - 如何让 SceneView 地图显示在 div 容器中?
- nginx - nginx won't resolve hostname in K8S
- google-sheets - 将公式值返回到单元格并添加到谷歌表格中的现有数据
- php - Laravel 5.3 中的内存不足错误
- google-sheets - Google 表格通配符不适用于 COUNTIF
- python - mongoengine 和 mLab 与 Elastic Beanstalk 自动缩放