note 99371 deleted from book.simplexml by danbrown
| From: | danbrown@php.net | Date: | Fri, 13 Aug 2010 10:48:12 +0000 |
| Subject: | note 99371 deleted from book.simplexml by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-171637@lists.php.net to get a copy of this message | ||
Note Submitter: Otto
----
SimpleXML by xananax at yelostudio dot com.
This function turns empty elements into Arrays. Fix below.
<?php
...
foreach ($xml->children() as $elementName => $child)
{
$value = simpleXMLToArray($child, $flattenValues, $flattenAttributes, $flattenChildren,
$valueKey, $attributesKey, $childrenKey);
if (isset($children[$elementName]))
{
if ($first)
{
$temp = $children[$elementName];
unset($children[$elementName]);
$children[$elementName][] = $temp;
$first=false;
}
$children[$elementName][] = $value;
}
else
{
// Fix for empty elements turning into Arrays
if (is_array($value))
{
if (!sizeof($value))
{
$value = "";
}
}
$children[$elementName] = $value;
}
}
...
?>