Posted By

jgomez on 03/28/12


Tagged

php object array function to


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

halk


objectToArray


 / Published in: PHP
 

URL: http://www.phpro.org/examples/Convert-Object-To-Array-With-PHP.html

From this URL : http://www.phpro.org/examples/Convert-Object-To-Array-With-PHP.html

  1. /**
  2.   *
  3.   * Convert an object to an array
  4.   * Also converts objects within objects / arrays
  5.   *
  6.   * @param object $object The object to convert
  7.   * @reeturn array
  8.   *
  9.   */
  10. public function objectToArray($data)
  11. {
  12. if(is_array($data) || is_object($data))
  13. {
  14. $result = array();
  15. foreach ($data as $key => $value)
  16. {
  17. $result[$key] = $this->objectToArray($value);
  18. }
  19. return $result;
  20. }
  21. return $data;
  22. }

Report this snippet  

You need to login to post a comment.