数组结果为单变量

时间:2016-11-17 10:38:45

标签: php arrays variables

我想使用下面的脚本计算邮政编码的运费。 这个脚本是一个带ups的运费计算器。 如何将数组结果放入单个$变量?

脚本代码:

$config = array(
    'weight' => 11, // Default = 1
    'weight_units' => 'lb', // lb (default), oz, gram, kg
    'size_length' => 11, // Default = 8
    'size_width' => 11, // Default = 4
    'size_height' => 11, // Default = 2
    'size_units' => 'in', // in (default), feet, cm
    'from_zip' => 97210, 
    'from_state' => "OR", // Only Required for FedEx
    'from_country' => "US",
    'to_zip' => 99745,
    'to_state' => "MN", // Only Required for FedEx
    'to_country' => "US",

    'ups_access' => '0C2D05F55AF310D0', // UPS Access License Key
    'ups_user' => 'dwstudios', // UPS Username  
    'ups_pass' => 'dwstudios', // UPS Password  
    'ups_account' => '81476R', // UPS Account Number
    'usps_user' => '229DARKW7858', // USPS User Name
    'fedex_account' => '510087020', // FedEX Account Number
    'fedex_meter' => '100005263' // FedEx Meter Number 
);

require_once "ShippingCalculator.php";
$ship = new ShippingCalculator($config);
$rates = $ship->calculate('ups','03'); // UPS Ground Shipping

print "
UPS Ground shipping rate for a ".$config['weight']." ".$config['weight_units'].", ".$config['size_length']." x ".$config['size_width']." x ".$config['size_height']." ".$config['size_units']." package from ".$config['from_zip']." to ".$config['to_zip'].":
<xmp>";
print_r($rates);
print "</xmp>";

1 个答案:

答案 0 :(得分:0)

您可以使用implode将数组的值放入一个变量中,如果这是您所追求的。