note 54914 added to function.simplexml-load-file
| From: | joelfielder at hotmail dot com | Date: | Tue, 19 Jul 2005 15:01:02 +0000 |
| Subject: | note 54914 added to function.simplexml-load-file | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-92170@lists.php.net to get a copy of this message | ||
In the object2array function posted above, the following data structure would be left unchanged:
Array
(
[0] => Object Object
(
[var] => 1
)
)
The simplexml_load_... functions return structures similar to the above, a simple example:
SimpleXMLElement Object
(
[USERS] => Array
(
[0] => SimpleXMLElement Object
(
[NAME] => Joel Fielder
[EMAIL] => joelfielder@hotmail.com
)
)
)
In order to store such information in the session, we have to convert all of the SimpleXMLElement
objects present in the structure:
Array
(
[USERS] => Array
(
[0] => Array
(
[NAME] => Joel Fielder
[EMAIL] => joelfielder@hotmail.com
)
)
)
And here is the code to do so:
<?php
function object2array($object)
{
$return = NULL;
if(is_array($object))
{
foreach($object as $key => $value)
$return[$key] = object2array($value);
}
else
{
$var = get_object_vars($object);
if($var)
{
foreach($var as $key => $value)
$return[$key] = object2array($value);
}
else
return $object;
}
return $return;
}
?>
----
Manual Page -- http://www.php.net/manual/en/function.simplexml-load-file.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+54914
Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+54914&report=yes&reason=added+to+the+manual
Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+54914&report=yes&reason=bad+code
Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+54914&report=yes&reason=spam
Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+54914&report=yes&reason=useless
Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+54914&report=yes&reason=non-english
Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+54914&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+54914&report=yes
Search -- http://master.php.net/manage/user-notes.php