Posted By

jodm on 08/04/09


Tagged

array xml


Versions (?)

Who likes this?

3 people have marked this snippet as a favorite

irishsk
umang_nine
dimispaceman


XML to Array


 / Published in: PHP
 

  1. function XML2Array($xml,$recursive = false) {
  2.  
  3. if (!$recursive ) { $array = simplexml_load_string ($xml); }
  4. else { $array = $xml ; }
  5.  
  6. $newArray = array();
  7. $array = $array ;
  8.  
  9. foreach ($array as $key => $value) {
  10. $value = (array) $value;
  11.  
  12. if (isset($value[0])) { $newArray[$key] = trim($value[0]); }
  13. else { $newArray[$key][] = XML2Array($value,true) ; }
  14. }
  15.  
  16. return $newArray;
  17. }

Report this snippet  

You need to login to post a comment.