note 81368 deleted from ref.simplexml by danbrown

From: Date: Mon, 18 May 2009 01:14:19 +0000
Subject: note 81368 deleted from ref.simplexml by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-155498@lists.php.net to get a copy of this message
Note Submitter: david at davidkmuir dot com ---- 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' ?>

« previous php.notes (#155498) next »