note 81368 added to ref.simplexml
| From: | david at davidkmuir dot com | Date: | Mon, 25 Feb 2008 03:22:43 +0000 |
| Subject: | note 81368 added to ref.simplexml | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-136467@lists.php.net to get a copy of this message | ||
mtudor: It is not worth including in the documentation, as it works exactly as expected.
Using Vegar's XML example (slightly modified):
<?php
$xml ="<doc>
<multi attr1='one' attr2='two' attr3='three'>One</multi>
<multi>Two</multi>
</doc>";
$xml = new SimpleXMLElement($xml);
echo count($xml->multi); //returns 2
echo count($xml->multi->attributes()); //returns 3
echo count($xml->multi[0]->attributes()); //returns 3
echo count($xml->multi[1]->attributes()); //returns 0
?>
So the only part that may throw people off is the fact that if an array key is not given, it will
assume the first element. This should however be obvious since you work from this assumption
whenever referring to a single element:
<?php
$xml ="<doc>
<single>
<tag>A Tag</tag>
</single>
</doc>";
$xml = new SimpleXMLElement($xml);
echo $xml->single[0]->tag[0]; //returns 'A Tag'
echo $xml->single->tag; //returns 'A Tag'
?>
----
Server IP: 117.104.160.194
Probable Submitter: 58.168.152.148
----
Manual Page -- http://www.php.net/manual/en/ref.simplexml.php
Edit -- https://master.php.net/note/edit/81368
Del: integrated -- https://master.php.net/note/delete/81368/integrated
Del: useless -- https://master.php.net/note/delete/81368/useless
Del: bad code -- https://master.php.net/note/delete/81368/bad+code
Del: spam -- https://master.php.net/note/delete/81368/spam
Del: non-english -- https://master.php.net/note/delete/81368/non-english
Del: in docs -- https://master.php.net/note/delete/81368/in+docs
Del: other reasons-- https://master.php.net/note/delete/81368
Reject -- https://master.php.net/note/reject/81368
Search -- https://master.php.net/manage/user-notes.php