sex = "nan";$obj->age = 12;$obj->addr">
时间:2021-07-01 10:21:17 帮助过:3人阅读
//1. 对象的遍历$obj = new stdClass();$obj->name = "lihua";$obj->sex = "nan";$obj->age = 12;$obj->address = "lihua in hanghzou!";foreach($obj as $v){ echo $v."
";}/* lihua nan 12 lihua in hanghzou!*///2.对象转数组//2.1.第一种方式$user = (array)$obj;var_dump($user);//2.2.第二种方式//简单而暴力的转换 只对public属性 有效//第二个参数 为 true 返回 数组// 为false 返回 对象$array = json_decode(json_encode($nested_object), true);//3.数组转对象(注意是关联数组)$user = (object)$user;var_dump($user);