Home > Backend Development > PHP Tutorial > PHP function to convert object to array (recursive method)

PHP function to convert object to array (recursive method)

WBOY
Release: 2016-07-25 09:03:21
Original
1028 people have browsed it
  1. function object_to_array($obj)
  2. {
  3. $_arr = is_object($obj) ? get_object_vars($obj) : $obj;
  4. foreach ($_arr as $key => $val)
  5. {
  6. $val = (is_array($val) || is_object($val)) ? object_to_array($val) : $val;
  7. $arr[$key] = $val;
  8. }
  9. return $arr;
  10. }
  11. ?>
复制代码


source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template