note 78829 added to function.array
| From: | MikeMackintosh at osu1 dot php dot net | Date: | Tue, 30 Oct 2007 05:38:28 +0000 |
| Subject: | note 78829 added to function.array | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-131820@lists.php.net to get a copy of this message | ||
If you need to add an object as an array key, for example an object from Simple XML Parser, you can
use the following.
File.XML
<?xml version="1.0" encoding="UTF-8"?>
<Settings type="General">
<Setting name="SettingName">This This This</Setting>
</Settings>
The script:
<?php
$raw = $xml = new SimpleXMLElement('File.XML');
foreach($raw->Setting as $A => $B)
{
// Set Array From XML
$Setting[(string) $B['name']] = (string) $B[0];
}
?>
By telling the key to read the object as a string, it will let you set it.
Hope this helps someone out!
----
Server IP: 209.41.74.194
Probable Submitter: 67.80.110.114
----
Manual Page -- http://www.php.net/manual/en/function.array.php
Edit -- https://master.php.net/note/edit/78829
Del: integrated -- https://master.php.net/note/delete/78829/integrated
Del: useless -- https://master.php.net/note/delete/78829/useless
Del: bad code -- https://master.php.net/note/delete/78829/bad+code
Del: spam -- https://master.php.net/note/delete/78829/spam
Del: non-english -- https://master.php.net/note/delete/78829/non-english
Del: in docs -- https://master.php.net/note/delete/78829/in+docs
Del: other reasons-- https://master.php.net/note/delete/78829
Reject -- https://master.php.net/note/reject/78829
Search -- https://master.php.net/manage/user-notes.php