我使用联邦快递的API为他们的商店查找“dropoff”位置,然后我将使用地图API(Google)显示。面向对象的PHP数组 - 从OO创建“位置”列表PHP数据
该API正在工作,但我有麻烦,因为我不熟悉面向对象的数组。
我想将数组中的值存储为唯一变量,因此我可以将它们传递给我的地图API。
我试图完成类似下面:
<?php
// MY "IDEAL" solution - any other ideas welcome
// (yes, reading up on Object Oriented PHP is on the to-do list...)
$response = $client ->fedExLocator($request);
if ($response -> HighestSeverity != 'FAILURE' && $response -> HighestSeverity != 'ERROR')
{
$response -> BusinessAddress -> StreetLines[0] = $location_0;
$response -> BusinessAddress -> StreetLines[1] = $location_1;
$response -> BusinessAddress -> StreetLines[2] = $location_2;
}
?>
工作联邦快递代码示例:
<?php
$response = $client ->fedExLocator($request);
if ($response -> HighestSeverity != 'FAILURE' && $response -> HighestSeverity != 'ERROR')
{
echo 'Dropoff Locations<br>';
echo '<table border="1"><tr><td>Streetline</td><td>City</td><td>State</td><td>Postal Code</td><td>Distance</td></tr>';
foreach ($response -> DropoffLocations as $location)
{
if(is_array($response -> DropoffLocations))
{
echo '<tr>';
echo '<td>'.$location -> BusinessAddress -> StreetLines. '</td>';
echo '<td>'.$location -> BusinessAddress -> PostalCode. '</td>';
echo '</tr>';
}
else
{
echo $location . Newline;
}
}
echo '</table>';
}
?>
你想要将位置存储到哪个数组?你也可以打印一个典型的'$ response'对象的var_dump吗? – 2012-08-14 21:13:36
你为什么要分配给从Fedex收到的'$ response'数组?这是你的数据*来源*。您应该将这些值分配给您自己的数据对象。 – 2012-08-14 21:14:38
试试'$ response-> DropOffLocations [0] - > BusinessAdress-> StreetLines [0]'而不是'$ response-> BusinessAdress-> StreetLines [0]'。 – jeremy 2012-08-14 21:15:00