所以我试图在php中集成fedex for web services。之前的表单获取包的接收者的所有必要项。我的所有代码一直工作,直到我尝试从表单中添加$ postal变量,如果我硬编码85308到'PostalCode'=> '85308'它有效,但是如果我用''。$ postal'替换'85308'''它不起作用。它给我错误消息:目的地邮政编码丢失或无效。
我已经在变量上使用了trim()改变了它的名字所有那些好东西仍然不行。
任何想法或意见都将非常感谢我的代码如下。
由于
<?php
//get address information$fname = $_POST["fname"];
$fname = $_POST["fname"];
$lname = $_POST["lname"];
$state = $_POST["state"];
$address1 = $_POST["address1"];
$address2 = $_POST["address2"];
$postal = $_POST["zip"];
$city = $_POST["city"];
$fullname = $fname." ".$lname;
$fulladdress = $address1." ".$address2;
function addRecipient(){
$recipient = array(
'Contact' => array(
'PersonName' => ''.$fullname.'',
'CompanyName' => 'Company Name',
'PhoneNumber' => '9012637906'
),
'Address' => array(
'StreetLines' => array(''.$fulladdress.''),
'City' => ''.$city.'',
'StateOrProvinceCode' => ''.$state.'',
//'PostalCode' => '85308',
'PostalCode' => ''.$postal.'',
'CountryCode' => 'US',
'Residential' => false)
);
return $recipient;
}
答案 0 :(得分:1)
在函数内部,变量超出了范围。见http://php.net/manual/en/language.variables.scope.php
解决方案: