我对PHP很新,我正在编写一个从SOAP中获取对象的PHP函数。 我发现了一个代码将其转换为数组,但我无法回显任何数据。
print_r
中的数组Array
(
[Status] => Array
(
[Code] => 0
[Message] => OK
)
[Order] => Array
(
[OrderNumber] => 9334543
[ExternalOrderNumber] =>
[OrderTime] => 2014-07-15T15:20:31+02:00
[PaymentMethod] => invoice
[PaymentStatus] => Paid
[ShipmentMethod] => Mypack
[DeliveryStatus] => Delivered
[Language] => sv
[Customer] => Array
(
[CustomerId] => 13556
[CustomerNumber] =>
[Username] => admin
[Approved] => 1
[OrgNumber] => 9309138445
[Company] =>
[VatNumber] =>
[FirstName] => Jane
[LastName] => Doe
[Address] => Gatan
[Address2] =>
[Zip] => 1230
[City] => Staden
[Country] => Sweden
[CountryCode] => SE
[PhoneDay] => 84848474
[PhoneNight] =>
[PhoneMobile] =>
[Email] => mail@msn.com
[NewsLetter] =>
[OrgType] => person
[OtherDelivAddress] =>
[DelivName] =>
[DelivAddress] =>
[DelivAddress2] =>
[DelivZip] =>
[DelivCity] =>
[DelivCountry] =>
[DelivCountryCode] =>
)
[Comment] =>
[Notes] => 9063025471 UK/MA
[CurrencyCode] => SEK
[ExchangeRate] => 1
[LanguagePath] => se
[FreightWithoutVat] => 0
[FreightWithVat] => 0
[FreightVatPercentage] => 25
[PayoptionFeeWithoutVat] => 0
[PayoptionFeeWithVat] => 0
[PayoptionFeeVatPercentage] => 25
[CodWithoutVat] => 0
[CodWithVat] => 0
[CodVatPercentage] => 0
[DiscountWithoutVat] => 0
[DiscountWithVat] => 0
[DiscountVat] => 0
[TotalWithoutVat] => 4388
[TotalWithVat] => 5485
[TotalVat] => 1097
[PayWithoutVat] =>
[AffiliateCode] =>
[AffiliateName] =>
[OrderField] => Array
(
[0] => Array
(
[Name] => external_ref
[Value] => 43445
)
[1] => Array
(
[Name] => webshopid
[Value] => 423
)
[2] => Array
(
[Name] => webshopname
[Value] => Manuell
)
)
)
)
非工作代码
echo $array[1][0]
我尝试了不同的索引组合。我知道如何从soap对象返回值,但如果我能这样做,它会更容易。应该不应该工作吗?
答案 0 :(得分:1)
$ array [1]是数组的第二个索引。这个数组的关键是" Status",这个数组包含一个代码和消息
我假设您想回复消息,您可以使用以下
来实现echo $array[1]["Status"]["Message"];
答案 1 :(得分:0)
尝试使用字符串键访问数组元素,而不是您正在使用的整数元素:
echo $array['Order']['Customer']['Address'];
另一种可以看到发生的事情的方法是迭代数组,并打印出键和值:
foreach ($array as $key => $value)
echo "Key=$key value=$value<br>";
答案 2 :(得分:0)
试
$array['Order']['Customer']['LastName']
是我最好的猜测而不会在那一行中失去理智。
但是,我们确保请发布print_r($array)
输出
答案 3 :(得分:0)
有一些方法我总是这样做:
print_r($array);
另一种方式是
$array[0]['Order']['LastName']
答案 4 :(得分:0)
您应该使用$array['Status']['Code']
,$array['Status']['Message']
,$array['Order']['OrderNumber']
,$array['Order']['Customer']['CustomerId']
等来显示您的数据。它是一个关联数组,因此您需要使用字符串键而不是数字