Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/282.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 要选择列表的命名空间对象_Php_Shipping_Fedex - Fatal编程技术网

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) 我可以看到这样的反应: ` ` 但我不知道如何才能让这些值显示在选择列表中。任何帮助都将不胜感激。以

我试图在我的网站上使用联邦快递配送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);
$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;