我正在调用一个返回以下数组的soap函数:
Array ( [FastAddressResult] => Array ( [IsError] => false [ErrorNumber] => 0 [ErrorMessage] => [Results] => Array ( [Address] => Array ( [Id] => 13872147.00 [OrganisationName] => [DepartmentName] => [Line1] => Methley Grove [Line2] => [Line3] => [Line4] => [Line5] => [PostTown] => Leeds [County] => West Yorkshire [Postcode] => LS7 3PA [Mailsort] => 64121 [Barcode] => [IsResidential] => false [IsSmallOrganisation] => false [IsLargeOrganisation] => false [RawData] => [GeographicData] => Array ( [GridEastM] => 0 [GridNorthM] => 0 [Objective2] => false [Transitional] => false [Longitude] => 0 [Latitude] => 0 [WGS84Longitude] => 0 [WGS84Latitude] => 0 ) ) ) )
我需要抽取以下似乎不起作用的值:
$this->adressline1 = $result->FastAddressResult->Results->Address->Line1;
答案 0 :(得分:6)
尝试:
$this->adressline1 = $result[ "FastAddressResult" ][ "Results" ][ "Address" ][ "Line1" ];
如果$ result是一个对象,你想要使用$ result-> fastAddressResult->等。有关PHP数组的更多信息,请查看this page。
此外,这种复杂阵列具有某些设计气味。您可以想出一种方法,使其更简单,更易读。
答案 1 :(得分:1)
显然有人在编程类中没有注意到它们覆盖数组......
$this->adressline1 = $result['FastAddressResult']['Results']['Address']['Line1'];
或首先将数组转换为stdClass:
$data = (object) $myarray;
但是你必须为那些所有阵列做到这一点,所以没有。
答案 2 :(得分:1)
像这样使用,
存储在一些名为$ res
的变量中的数组 echo $res[ "FastAddressResult" ][ "Results" ][ "Address" ][ "Line1" ];