PHP 8.5.0 Alpha 4 available for testing

Voting

: max(four, nine)?
(Example: nine)

The Note You're Voting On

php-lover at live dot com
9 years ago
Function to extract SimpleXMLElement data to array.

function extract($sxe = null) {
if (!$sxe instanceOf SimpleXMLElement)
return array();

$extract = array();

foreach ($sxe->children() as $key => $value) {
if (array_key_exists($key, $extract)) {
if (!isset($extract[$key][0])) {
$tmp_extract = $extract[$key];
$extract[$key] = array();
$extract[$key][0] = $tmp_extract;
} else
$extract[$key] = (array) $extract[$key];
}

if ($value->count()) {
if (isset($extract[$key]) && is_array($extract[$key]))
$extract[$key][] = $this->extract($value);
else
$extract[$key] = $this->extract($value);
} else {
if (isset($extract[$key]) && is_array($extract[$key]))
$extract[$key][] = empty(strval($value)) ? null : strval($value);
else
$extract[$key] = empty(strval($value)) ? null : strval($value);
}
}

return $extract;
}

<< Back to user notes page

To Top