如何将PHP对象转换为数组?

更新于
2026-09-24 17:49:56
1阅读来源:SEO问题
  • 内容介绍
  • 文章标签
  • 相关推荐

本文共计68个文字,预计阅读时间需要1分钟。

如何将PHP对象转换为数组?

使用PHP将对象转换为数组,可以通过以下代码实现:

phpfunction obj_to_array($obj) { if (!is_object($obj) && !is_array($obj)) { return []; } return json_decode(json_encode($obj), true);}

如何将PHP对象转换为数组?

PHP 对象转数组

/** * 对象转换为数组 * @param $obj * @return array */ function obj_to_array($obj) { if (!is_object($obj) && !is_array($obj)) { return []; } return json_decode(json_encode($obj), true); }