0
点赞
收藏
分享

微信扫一扫

thinkphp5 select对象怎么转数组?

GG_lyf 2023-01-11 阅读 99


DB操作返回是数组。模型直接操作返回是对象 
对象类型转换数组
打开 database.php 增加或修改参数
'resultset_type' => '\think\Collection',
即可连贯操作
model('user')->select()->toArray()

可是这样很麻烦!!!!!

因为 如果 数据为空, ->toArray()   会报错

当然,如果用 if 判断也可

thinkphp5 select对象怎么转数组?_数组

thinkphp5 select对象怎么转数组?_数组_02

 

强制转换成数组,一劳永逸

举报

相关推荐

0 条评论