我希望你能帮助查明我在下面的代码犯错误:空数组输出结果
public function yee() {
$json = array();
$params = array(
'token' => $this->_token,
'receiver_name' => 'Test Name',
'sender_city' => 'copenhagen',
'sender_country' => 'DK',
'order_id' => 150
);
$ch = curl_init();
$query = http_build_query($params);
curl_setopt($ch, CURLOPT_URL, self::API_ENDPOINT . '/' . 'shipments/imported_shipment');
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $query);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$output = curl_exec ($ch);
$http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close ($ch);
$output = json_decode($output, true);
if ($http_code != 200){
if(is_array($output['message'])){
$json['error'] = $output['message'];
}else{
$json['error'] = $output['message'];
}
} else {
$json['error'] = "Import Successully";
}
return $output;
}
}
我有这个在我的class.php文件,有几行做认证一起。
然后我尝试对其进行初始化后调用的函数:
$testObject->yee();
echo $testObject->yee(); ?>
认证部分正常工作,因为我还输出令牌和其他一些变量,但是当我回声仪()函数 - 它显示的是“阵列”
如果您没有注意到,我在JSON/API领域非常环保,而且我的PHP技能最多只会生锈。所以我希望任何指标都能让我更接近解决这个问题。谢谢!
那是因为返回值是一个数组!你不能回显数组。如果你只是想查看它的内容以进行调试,那么用户'var_dump($ output);' – Steve 2015-04-02 10:27:53
非常感谢,现在我觉得它是这样的。 似乎很好地处理了输出的var_dump,并且假设我正在调试时是正确的。再次,非常感谢! – Mark 2015-04-02 10:39:16