摘录手册一段,留意红色部分: ------------------------------------------------------- The SimpleXMLElement class (No version information available, might only be in SVN) 简介 Represents an element in an XML document. 类摘要 SimpleXMLElement implements Traversable { …… -----------------------------------------------------------------Traversable 是SPL的一个类(目前手册并无具体介绍,但去 php.net 能发掘到) 再摘录一小段给你-----------------------------------------------------------------------------Traversable Interface Reference [Zend engine classes] Interface to detect a class is traversable using foreach. More...Detailed Description Interface to detect a class is traversable using foreach. //这就意味着是可迭代对象Since: PHP 5.0 Abstract base interface that cannot be implemented alone. Instead it must be implemented by either IteratorAggregate or Iterator.Note: Internal classes that implement this interface can be used in a foreach construct and do not need to implement IteratorAggregate or Iterator. This is an engine internal interface which cannot be implemented in PHP scripts. Either IteratorAggregate or Iterator must be used instead. Definition at line 509 of file spl.php. -------------------------------------------------------------------------------- The documentation for this interface was generated from the following file: spl.php
(
[0] => SimpleXMLElement Object
(
[@attributes] => Array
(
[lang] => 中文
) [name] => 如何成功?
[author] => 张三
[price] => 39.8
)
-------------------------------------------------------
The SimpleXMLElement class
(No version information available, might only be in SVN)
简介
Represents an element in an XML document.
类摘要
SimpleXMLElement implements Traversable {
……
-----------------------------------------------------------------Traversable 是SPL的一个类(目前手册并无具体介绍,但去 php.net 能发掘到)
再摘录一小段给你-----------------------------------------------------------------------------Traversable Interface Reference
[Zend engine classes]
Interface to detect a class is traversable using foreach. More...Detailed Description
Interface to detect a class is traversable using foreach. //这就意味着是可迭代对象Since:
PHP 5.0
Abstract base interface that cannot be implemented alone. Instead it must be implemented by either IteratorAggregate or Iterator.Note:
Internal classes that implement this interface can be used in a foreach construct and do not need to implement IteratorAggregate or Iterator.
This is an engine internal interface which cannot be implemented in PHP scripts. Either IteratorAggregate or Iterator must be used instead.
Definition at line 509 of file spl.php.
--------------------------------------------------------------------------------
The documentation for this interface was generated from the following file:
spl.php
一般用遍历 attributes 方法返回的数组进行操作
你那样写也是可以的