如何获取simplexmlobject php的位置
我有以下简单的 xml 对象文件:
[AuthorList] => SimpleXMLElement Object
(
[@attributes] => Array
(
[CompleteYN] => Y
)
[Author] => Array
(
[0] => SimpleXMLElement Object
(
[@attributes] => Array
(
[ValidYN] => Y
)
[LastName] => van Tricht
[ForeName] => M J
[Initials] => MJ
)
[1] => SimpleXMLElement Object
(
[@attributes] => Array
(
[ValidYN] => Y
)
[LastName] => Nieman
[ForeName] => D H
[Initials] => DH
)
[2] => SimpleXMLElement Object
(
[@attributes] => Array
(
[ValidYN] => Y
)
[LastName] => Bour
[ForeName] => L J
[Initials] => LJ
)
[3] => SimpleXMLElement Object
(
[@attributes] => Array
(
[ValidYN] => Y
)
[LastName] => Boerée
[ForeName] => T
[Initials] => T
)
[4] => SimpleXMLElement Object
(
[@attributes] => Array
(
[ValidYN] => Y
)
[LastName] => Koelman
[ForeName] => J H T M
[Initials] => JH
)
[5] => SimpleXMLElement Object
(
[@attributes] => Array
(
[ValidYN] => Y
)
[LastName] => de Haan
[ForeName] => L
[Initials] => L
)
[6] => SimpleXMLElement Object
(
[@attributes] => Array
(
[ValidYN] => Y
)
[LastName] => Linszen
[ForeName] => D H
[Initials] => DH
)
)
)
现在我想输出一个名字的位置,例如
位置 LastName Boeree 是 2 0f 6
(0 是起始索引)
有谁知道这一点吗?
I have the following simple xml object file:
[AuthorList] => SimpleXMLElement Object
(
[@attributes] => Array
(
[CompleteYN] => Y
)
[Author] => Array
(
[0] => SimpleXMLElement Object
(
[@attributes] => Array
(
[ValidYN] => Y
)
[LastName] => van Tricht
[ForeName] => M J
[Initials] => MJ
)
[1] => SimpleXMLElement Object
(
[@attributes] => Array
(
[ValidYN] => Y
)
[LastName] => Nieman
[ForeName] => D H
[Initials] => DH
)
[2] => SimpleXMLElement Object
(
[@attributes] => Array
(
[ValidYN] => Y
)
[LastName] => Bour
[ForeName] => L J
[Initials] => LJ
)
[3] => SimpleXMLElement Object
(
[@attributes] => Array
(
[ValidYN] => Y
)
[LastName] => Boerée
[ForeName] => T
[Initials] => T
)
[4] => SimpleXMLElement Object
(
[@attributes] => Array
(
[ValidYN] => Y
)
[LastName] => Koelman
[ForeName] => J H T M
[Initials] => JH
)
[5] => SimpleXMLElement Object
(
[@attributes] => Array
(
[ValidYN] => Y
)
[LastName] => de Haan
[ForeName] => L
[Initials] => L
)
[6] => SimpleXMLElement Object
(
[@attributes] => Array
(
[ValidYN] => Y
)
[LastName] => Linszen
[ForeName] => D H
[Initials] => DH
)
)
)
Now i want to output the position of one name, for example
position LastName Boeree is 2 0f 6
(0 is the starting index)
Does anyone know this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用 for 循环。
可以说 $authorList 是您的 simpleXML 对象
编辑:编辑代码以使用 simpleXML 对象而不是数组
Use a for loop.
Lets say $authorList is your simpleXML object
EDIT: edited code to use the simpleXML object instead of an array