谁一开始就是大神?

请问获取到object类型的数据如何转换成数组[2.0]

是object类型,不是std Object这种
如下:

object(test\myyii\models\Customer)#67 (8) { ["_attributes":"yii\db\BaseActiveRecord":private]=> array(7) { ["id"]=> int(7) ["username"]=> string(6) "老王" ["admin_id"]=> string(1) "0" ["company_id"]=> string(1) "2" ["id_card"]=> string(18) "510321199201012234" ["telphone"]=> string(11) "15877556633" ["created_at"]=> int(1467104334) } ["_oldAttributes":"yii\db\BaseActiveRecord":private]=> array(7) { ["id"]=> int(7) ["username"]=> string(6) "老王" ["admin_id"]=> string(1) "0" ["company_id"]=> string(1) "2" ["id_card"]=> string(18) "510321199201012234" ["telphone"]=> string(11) "15877556633" ["created_at"]=> int(1467104334) } ["_related":"yii\db\BaseActiveRecord":private]=> array(0) { } ["_errors":"yii\base\Model":private]=> NULL ["_validators":"yii\base\Model":private]=> NULL ["_scenario":"yii\base\Model":private]=> string(7) "default" ["_events":"yii\base\Component":private]=> array(0) { } ["_behaviors":"yii\base\Component":private]=> array(0) { } }

ActiveRecord:查询的直接加上asArray();
$userAll = User::find()->asArray()->all();
这对象本身就可以当数组用,因为他实现了ArrayAccess接口

赞(0) 打赏
未经允许不得转载:菜鸟之家 » 请问获取到object类型的数据如何转换成数组[2.0]

评论 抢沙发

登录

找回密码

注册