如何将PHP对象转换为数组?
- 内容介绍
- 文章标签
- 相关推荐
本文共计68个文字,预计阅读时间需要1分钟。
使用PHP将对象转换为数组,可以通过以下代码实现:
phpfunction obj_to_array($obj) { if (!is_object($obj) && !is_array($obj)) { return []; } return json_decode(json_encode($obj), true);}
/** * 对象转换为数组 * @param $obj * @return array */ function obj_to_array($obj) { if (!is_object($obj) && !is_array($obj)) { return []; } return json_decode(json_encode($obj), true); }
本文共计68个文字,预计阅读时间需要1分钟。
使用PHP将对象转换为数组,可以通过以下代码实现:
phpfunction obj_to_array($obj) { if (!is_object($obj) && !is_array($obj)) { return []; } return json_decode(json_encode($obj), true);}
/** * 对象转换为数组 * @param $obj * @return array */ function obj_to_array($obj) { if (!is_object($obj) && !is_array($obj)) { return []; } return json_decode(json_encode($obj), true); }

