在变量类别的帮助下,我有了这个数组,其中所有数组都没有键/默认索引,因此当我在 foreach 中将 $categories 作为 $category 执行时以及当我 echo $category['name'] 时给出非法的刺痛补偿。
使用 Laravel Blade
可能的解决方案是什么,或者我应该首先验证数组?
最佳答案
以上代码为JSON格式,先转为数组
例如
$ex = {
'result':"success",
'categories':[{
//your rest of the code
}]
}
$data = json_decode($ex, TRUE);
//next use for each
foreach($data as $key => $value)
{
//rest of your logic
}
关于php - 非法字符串偏移 'name' php - 许多数组变成 1 个数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47766135/