Php 要选择列表的命名空间对象
我试图在我的网站上使用联邦快递配送api。我不擅长php,当我尝试代码时Php 要选择列表的命名空间对象,php,shipping,fedex,Php,Shipping,Fedex,我试图在我的网站上使用联邦快递配送api。我不擅长php,当我尝试代码时 $calculator=new-MediaLab\Shipping\calculator\FedExCalculator($key、$password、$accountNumber、$meterNumber); $calculator->Calculation($source,$destination,$Shipping) 我可以看到这样的反应: ` ` 但我不知道如何才能让这些值显示在选择列表中。任何帮助都将不胜感激。以
$calculator=new-MediaLab\Shipping\calculator\FedExCalculator($key、$password、$accountNumber、$meterNumber);
$calculator->Calculation($source,$destination,$Shipping)代码>
我可以看到这样的反应:
`
`
但我不知道如何才能让这些值显示在选择列表中。任何帮助都将不胜感激。以下内容应构建一个选择框以显示结果:
$calculator = new MediaLab\Shipping\Calculator\FedExCalculator($key,$password, $accountNumber, $meterNumber);
$results = $calculator->calculate($source, $destination, $shipment);
var $html = '<select>';
foreach ($results as $result) {
$cost = $result->getCost()->getCurrency() . $result->getCost()->getAmount();
$html .= '<option name="' . $result->getServiceCode() . '">' . $result->getCarrier() . ' - ' . $result->getServiceName() . ' - ' . $result->getDeliveryDate() . ' - ' . $cost . '</option>';
}
$html = '</select>';
echo $html;
$calculator=new-MediaLab\Shipping\calculator\FedExCalculator($key、$password、$accountNumber、$meterNumber);
$results=$calculator->calculation($source,$destination,$shipping);
var$html='';
foreach($results作为$result){
$cost=$result->getCost()->getCurrency()。$result->getCost()->getAmount();
$html.='.$result->getCarrier().-'.$result->getServiceName().-'.$result->getDeliveryDate().-'.$cost';
}
$html='';
echo$html;
基本上,您可以循环遍历结果,并使用对象提供的方法来获取所需的数据。查看所有可用方法的类接口可能会有所帮助。@charlie您能完美地回答这个问题吗。这正是我想要的。上帝保佑你。
$calculator = new MediaLab\Shipping\Calculator\FedExCalculator($key,$password, $accountNumber, $meterNumber);
$results = $calculator->calculate($source, $destination, $shipment);
var $html = '<select>';
foreach ($results as $result) {
$cost = $result->getCost()->getCurrency() . $result->getCost()->getAmount();
$html .= '<option name="' . $result->getServiceCode() . '">' . $result->getCarrier() . ' - ' . $result->getServiceName() . ' - ' . $result->getDeliveryDate() . ' - ' . $cost . '</option>';
}
$html = '</select>';
echo $html;