note 45998 added to ref.simplexml
| From: | majkqball_gmail_com at osu1 dot php dot net | Date: | Sat, 25 Sep 2004 22:44:49 +0000 |
| Subject: | note 45998 added to ref.simplexml | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-77325@lists.php.net to get a copy of this message | ||
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.
----
Manual Page -- http://www.php.net/manual/en/ref.simplexml.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+45998
Delete -- http://master.php.net/manage/user-notes.php?action=delete+45998&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+45998&report=yes
Search -- http://master.php.net/manage/user-notes.php