note 101916 added to class.simplexmliterator
| From: | marcvangend at osu1 dot php dot net | Date: | Tue, 18 Jan 2011 09:38:05 +0000 |
| Subject: | note 101916 added to class.simplexmliterator | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-175848@lists.php.net to get a copy of this message | ||
Thanks ratfactor. Here is a slightly modified version of your sxiToArray function which supports
attributes.
<?php
function sxiToArray($sxi) {
$a = array();
for ($sxi->rewind(); $sxi->valid(); $sxi->next()) {
if (!array_key_exists($sxi->key(), $a)) {
$a[$sxi->key()] = array();
}
if ($sxi->hasChildren()) {
$a[$sxi->key()][] = sxiToArray($sxi->current());
}
else {
$attr = array();
foreach ($sxi->current()->attributes() as $key => $value) {
$attr[$key] = strval($value);
}
$a[$sxi->key()][] = array(
'@value' => strval($sxi->current()),
'@attributes' => $attr,
);
}
}
return $a;
}
?>
----
Server IP: 69.147.83.197
Probable Submitter: 80.113.7.34
----
Manual Page -- http://www.php.net/manual/en/class.simplexmliterator.php
Edit -- https://master.php.net/note/edit/101916
Del: integrated -- https://master.php.net/note/delete/101916/integrated
Del: useless -- https://master.php.net/note/delete/101916/useless
Del: bad code -- https://master.php.net/note/delete/101916/bad+code
Del: spam -- https://master.php.net/note/delete/101916/spam
Del: non-english -- https://master.php.net/note/delete/101916/non-english
Del: in docs -- https://master.php.net/note/delete/101916/in+docs
Del: other reasons-- https://master.php.net/note/delete/101916
Reject -- https://master.php.net/note/reject/101916
Search -- https://master.php.net/manage/user-notes.php