0

我正在调用一个返回以下数组的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;
4

3 回答 3

6

尝试:

$this->adressline1 = $result[ "FastAddressResult" ][ "Results" ][ "Address" ][ "Line1" ];

如果 $result 是一个对象,你会想使用 $result->fastAddressResult->etc。查看此页面以获取有关 PHP 数组的更多信息。

此外,这种复杂的阵列具有一定的设计气味。你可以想办法让它更简单、更易读。

于 2010-04-27T08:04:10.373 回答
1

像这样使用,

数组存储在称为 $res 的某个变量中

   echo $res[ "FastAddressResult" ][ "Results" ][ "Address" ][ "Line1" ];
于 2010-04-27T08:11:53.797 回答
1

很明显,有人在编程课上讲数组时没有注意……

$this->adressline1 = $result['FastAddressResult']['Results']['Address']['Line1'];

或先将数组转换为 stdClass:

$data = (object) $myarray;

但是您也必须对其中的所有数组都这样做,所以不。

于 2010-04-27T08:06:55.367 回答