note 64837 modified in function.simplexml-element-children by danbrown
| From: | danbrown@php.net | Date: | Wed, 16 Sep 2009 15:34:35 +0000 |
| Subject: | note 64837 modified in function.simplexml-element-children by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-160638@lists.php.net to get a copy of this message | ||
Sometimes you actually want an array, not a pseudo array. This is especially true when you
aren't dealing with attributes (i.e., you just want the array of child nodes).
Do like this:
<?php
$children = $sxml->xpath('child::node()');
?>
The reason you might want this is to be able to use array functions like array_shift, array_pop,
etc. This is especially true when you are writing recursive functions. Simplexml works really well
in iterative programming, but if you try to implement recursion it gets ugly.
--was--
Sometimes you actually want an array, not a pseudo array. This is especially true when you
aren't dealing with attributes (i.e., you just want the array of child nodes).
Do like this:
<?php
$children = $sxml->xpath('child::node()');
?>
The reason you might want this is to be able to use array functions like array_shift, array_pop,
etc. This is especially true when you are writing recursive functions. Simplexml works really well
in iterative programming, but if you try to implement recursion it gets ugly.
http://php.net/manual/en/function.simplexml-element-children.php