我正在使用 FedEx 的 API 为他们的商店查找“下车”位置,然后我将使用地图 API (Google) 显示这些位置。
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>';
}
?>