简体   繁体   中英

array result to single variable

I want to calculate the costs for shipping by zipcode using the script below. This script is a shipping calculator with ups. How can I put the array result into a single $variable?

The script code:

$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>";

您可以使用implode将数组的值放到一个变量中。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM