php Illegal string offset 'name'问题及解决

2022-07-19 15:13:28

目录phpIllegalstringoffsetname解决办法thinkphp:Illegalstringoffsetinxxxx解决办法很简单phpIllegalstring...

目录
php Illegal string offset 'name'
解决办法
thinkphp:Illegal string offset in 'xxxx'
解决办法很简单

php Illegal string offset 'name'

php Illegal string offset 'name'问题及解决

上面代码可以输出值,但是

报错Warning: Illegal string offset 'name' in 

原因是$person数组里面有空数组,空数组里没有name这个字段php

解决办法

是在 foreach 下面加个判断 if(is_array($value)),这样就搞定了。

   $name = array();
    foreach ($person as $value) {
    if(is_array($value))
    {
    $name[] = $value['name'];
    }
    
    }

thinkphp:Illegal string offset in 'xxxx'

php Illegal string offset 'name'问题及解决

php Illegal string offset 'name'问题及解决

php Illegal string offset 'name'问题及解决

在使用thinkphp5遇到这个问题 特地记录下。。

在排除各种什么不能用空数组做索引等原因之后,猛然发现volist标签是输出二维数组的。

而find方法返回的是一维数组。。。(*  ̄︿ ̄),当然,你也可以所有都用select方法

解决办法很简单

一维数组直接{关联数组的索引}输出 {$bp.id}  二维数组再用volist

以上为js个人经验,希望能给大家一个参考,也希望大家多多支持我们。

相关文章 大家在看