开发者

SimpleXml PHP addchild before any child [duplicate]

This question already has answers here: SimpleXML how to prepend a child in a node? (3 answers) Closed 1 year ago.

I know how to add child nodes with SimpleXml and PHP but i have a problem with the orders of those child elements. Lets say i have this xml structure

album gallery1 galler开发者_运维百科y2 gallery2 . . . galleryN /album

This is how it is right now when I add childs with the basic code

$galleryElement = $sxe->addChild("gallery"); 

I want the order of child elements in this case to be on the opposite the last gallery that i will add to be first child of Album.

example:

album gallery3 gallery2 gallery1

/album

Any one knows some trick here


It looks like you want to prepend to your container. Unfortunately simplexml doesn't have this function natively, but this previous answer will assist you in getting it working

SimpleXML how to prepend a child in a node?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜