php 中的多维数组 - 有两个同名的数组?
基本上构建一个 SOAP 客户端,部分所需输入的格式如下:
<Attributes>
<Attribute>
<AttributeType>HomeType</AttributeType>
<Value>duplex</Value>
</Attribute>
<Attribute>
<AttributeType>Bedrooms</AttributeType>
<Value>2</Value>
</Attribute>
<Attribute>
<AttributeType>Bathrooms</AttributeType>
<Value>2</Value>
</Attribute>
</Attributes>
这是通过数组发布的:
$homeType = array (
'AttributeType' => 'HomeType',
'Value' => $_POST['hometype']
);
$bedrooms = array (
'AttributeType' => 'Bedrooms',
'Value' => $_POST['bedrooms']
);
$bathrooms = array(
'AttributeType' => 'Bathrooms',
'Value' => $_POST['bathrooms']
);
$attributes = array (
'Attribute' => $homeType,
'Attribute' => $bedrooms,
'Attribute' => $bathrooms
);
正如您可以想象的,所有数组返回的是最后一个属性,因此 xml 看起来像:
<Attributes>
<Attribute>
<AttributeType>Bathrooms</AttributeType>
<Value>2</Value>
</Attribute>
</Attributes>
我无法想象解决这个问题的任何实用方法,因为属性可以计数到 30-50,所以我不想用数字键它们,特别是因为数组仅被称为:
'Attributes' => $attributes,
任何帮助将不胜感激!
Basically building a SOAP Client, and part of the required input is formatted as so:
<Attributes>
<Attribute>
<AttributeType>HomeType</AttributeType>
<Value>duplex</Value>
</Attribute>
<Attribute>
<AttributeType>Bedrooms</AttributeType>
<Value>2</Value>
</Attribute>
<Attribute>
<AttributeType>Bathrooms</AttributeType>
<Value>2</Value>
</Attribute>
</Attributes>
This is posted via an Array:
$homeType = array (
'AttributeType' => 'HomeType',
'Value' => $_POST['hometype']
);
$bedrooms = array (
'AttributeType' => 'Bedrooms',
'Value' => $_POST['bedrooms']
);
$bathrooms = array(
'AttributeType' => 'Bathrooms',
'Value' => $_POST['bathrooms']
);
$attributes = array (
'Attribute' => $homeType,
'Attribute' => $bedrooms,
'Attribute' => $bathrooms
);
And as you can imagine, all the Array returns is the last attribute, so the xml looks like:
<Attributes>
<Attribute>
<AttributeType>Bathrooms</AttributeType>
<Value>2</Value>
</Attribute>
</Attributes>
I can't think of any practical way around this, as the Attributes can count up to 30-50, so I don't want to numerically key them, especially as the array is only called as:
'Attributes' => $attributes,
Any help would be massively appreciated!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
难道你不应该只使用一个数组吗?
$属性=数组(
'属性' =>数组($homeType,$bedrooms,$bathrooms)
);
Shouldn't you just use an array?
$attributes = array(
'Attribute' => array($homeType, $bedrooms, $bathrooms)
);