php - How do I loop a nested array in laravel to get an array based on conditions of key values from that array
问题描述
I want to get only the arrays where the option is not null When i get the arrays back successfully, i also want to add it to a database, but most importantly i want to get the arrays back
array:3 [
0 => array:5 [
"id" => 6
"option" => "True"
"is_correct" => true
"label" => "True"
"opid" => 1
]
1 => array:5 [
"id" => 7
"option" => "False"
"is_correct" => false
"label" => "False"
"opid" => 1
]
2 => array:5 [
"id" => 8
"option" => null
"is_correct" => false
"label" => "Theory"
"opid" => 5
]
]
EXPECTED RESULT
array:3 [
0 => array:5 [
"id" => 6
"option" => "True"
"is_correct" => true
"label" => "True"
"opid" => 1
]
1 => array:5 [
"id" => 7
"option" => "False"
"is_correct" => false
"label" => "False"
"opid" => 1
]
]
WHAT I HAVE TRIED
foreach($request->option as $option) {
if($option["option"] == null){
dd($option)
}
}
i only get the first value from the array.. it appears like my if condition is not working as well
i'll be in the comments thank you
解决方案
Try except
method,
Read documentation - https://laravel.com/docs/8.x/eloquent-collections#method-contains
推荐阅读
- javascript - 在标准 JS 文件中包含节点模块
- c - C中openssl RSA_public_encrypt()的段错误
- python - pandas 应用自定义函数问题('if' 语句不起作用)
- python - 将 TextInput 绑定到 .kv 文件中的标签
- php - 从 wordpress 仪表板中删除站点统计信息和 Elementor 小部件
- r - 计算一组列中存在的唯一字符
- react-native - 解析 React Native 的内部模块需要哪些 Metro bundler 设置?
- java - 检查两个对象是否相等,不包括一些属性
- arrays - 按双值Swift对字典进行排序
- java - 如何比较 Java 中的值数组以找到列表中的最大值?