Home > Backend Development > PHP Tutorial > PHP code to convert object to array function

PHP code to convert object to array function

WBOY
Release: 2016-07-25 09:04:50
Original
875 people have browsed it
  1. /**
  2. * Convert object to array
  3. * link: bbs.it-home.org
  4. * date: 2013/2/22
  5. */
  6. function object_to_array($obj)
  7. {
  8. $_arr = is_object($obj) ? get_object_vars($obj) : $obj;
  9. foreach ($_arr as $key => $val)
  10. {
  11. $val = (is_array($val) || is_object($val)) ? object_to_array($val) : $val;
  12. $arr[$key] = $val;
  13. }
  14. return $arr;
  15. }
  16. ?>
复制代码


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