在 PHP 的请求中指定同名的子级
我需要构建一个与此类似的请求:
<rooms>
<room>12345</room>
<room>65679</room>
</rooms>
但是,我插入一个房间,例如:
$request->therequest->rooms['room'] = 123456;
但是当我为第二个房间再次执行此操作时,它会覆盖第一个房间。如何在“房间”下指定 2 个儿童“房间”而不覆盖它们?
谢谢!这与一些 SoapClient 的东西一起工作。
I need to build a request similar to this:
<rooms>
<room>12345</room>
<room>65679</room>
</rooms>
However, I insert one room like:
$request->therequest->rooms['room'] = 123456;
But when I do it again for the 2nd one, it overwrites the first one. How can I specify 2 children 'room' under 'rooms' without overwriting them?
Thanks! This is working with some SoapClient stuff.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您应该考虑使用
SimpleXMLElement
。那么你只需这样做:输出将是:
阅读有关 SimpleXMLElement 的更多信息< /a>.这里有一些关于addChild 方法的更多信息。
You should consider using
SimpleXMLElement
. Then you would just do this:And the output would be:
Read more about SimpleXMLElement here. And here's some more info on the addChild method.
您需要创建一系列房间。
您可以将其添加到数组中,如下所示:
You need to create an array of rooms.
You can add it to the array like:
$request->therequest->rooms['room'][0]
怎么样?What about
$request->therequest->rooms['room'][0]
?