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

来自:网络
时间:2023-01-03
阅读:
目录

php Illegal string offset 'name'

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

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

报错Warning: Illegal string offset 'name' in 

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

解决办法

是在 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

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

返回顶部
顶部