note 45998 deleted from ref.simplexml by derick

From: Date: Thu, 13 Oct 2005 13:47:28 +0000
Subject: note 45998 deleted from ref.simplexml by derick
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-96956@lists.php.net to get a copy of this message
Note Submitter: majkqball_gmail_com ---- Converting SimpleXML objects to an array: <?php $sx = simplexml_load_string('your xml string here'); function recursive_obj2array($obj, &$subject_array=array()) { foreach ((array) $obj as $key => $var) { if (is_object($var)) { if(count((array) $var) == 0) { $subject_array[$key] = 'NULL'; } else { recursive_obj2array($var, $subject_array[$key]); } } else { $subject_array[$key] = $var; } } } $gimmie = array(); recursive_obj2array($sx, $gimmie); ?> Then $gimmie is foreach friendly. Quick and dirty, but rather effective.

« previous php.notes (#96956) next »