Posted By

wza on 09/09/10


Tagged

php textmate array xml Objects simplexml


Versions (?)

objects into array


 / Published in: PHP
 

  1. function objectsIntoArray($arrObjData, $arrSkipIndices = array())
  2. {
  3. $arrData = array();
  4.  
  5. // if input is object, convert into array
  6. if (is_object($arrObjData)) {
  7. $arrObjData = get_object_vars($arrObjData);
  8. }
  9.  
  10. if (is_array($arrObjData)) {
  11. foreach ($arrObjData as $index => $value) {
  12. if (is_object($value) || is_array($value)) {
  13. $value = objectsIntoArray($value, $arrSkipIndices); // recursive call
  14. }
  15. if (in_array($index, $arrSkipIndices)) {
  16. continue;
  17. }
  18. $arrData[$index] = $value;
  19. }
  20. }
  21. return $arrData;
  22. }

Report this snippet  

You need to login to post a comment.