I am trying to build a dynamic array for a 3rd party shipping software. It would an array with package information for each box we're shipping through UPS. I had it working earlier or, I thought I did.
Here is an example of an success for call where is parcel element is a new box.
"from_address" => $from_address_params,
"to_address" => $to_address_params,
"shipments" => array(
array(
"parcel" => array("length" => null, "width" => null, "height" => null, "weight" => 12)
),
array(
"parcel" => array("length" => null, "width" => null, "height" => null, "weight" => 13)
),
),
That works fine and return the correct rates base on multiple boxes.
Here is how I am trying to build this array.
$arr = '';
for($i=0; $i<$numBoxes; $i++){
$arr .= '"parcel" => array("length" => null, "width" => null, "height" => null, "weight" => '.$indiBoxW.')';
if($i + 1 < $numBoxes){
$arr .= ', ';
}
else{
$arr .= '';
}
}
Then add that array like this:
"from_address" => $from_address_params,
"to_address" => $to_address_params,
"shipments" => array(
$arr
),
));