[英]Retrieve an array of invoices instead of an object PHP
我正在尝试检索每个客户的发票列表。 到目前为止,我只检索列表的第一个 object。 但是我如何检索整个列表? 我是 PHP 的初学者,所以我真的想不通,Chargebee 的文档也没有为我澄清任何事情。
以下是文档: https://apidocs.eu.chargebee.com/docs/api/invoices?prod_cat_ver=2&lang=php#list_invoices
这是我到目前为止尝试过的:
$customerID = $_POST['customerID'];
require_once(dirname(__FILE__) . '/chargebee-php-2.8.3/lib/ChargeBee.php');
ChargeBee_Environment::configure("xxxx","xxxx");
$result = ChargeBee_Invoice::all(array(
"limit" => 13,
"sortBy[desc]" => "date",
"customerId[is]" => (string)$customerID
));
foreach($result as $entry){
$invoice = $entry->invoice();
}
$array = (array) $invoice;
echo json_encode($array);
不幸的是,我只检索列表的第一项。 如何获取数组中的整个列表,但编码为 json 字符串?
您不断覆盖$invoice
变量。
创建并清空数组并将每张发票推送到该数组上应该会产生您想要的结果。 所以试试这个:
$customerID = $_POST['customerID'];
require_once(dirname(__FILE__) . '/chargebee-php-2.8.3/lib/ChargeBee.php');
ChargeBee_Environment::configure("xxxx","xxxx");
$result = ChargeBee_Invoice::all(array(
"limit" => 13,
"sortBy[desc]" => "date",
"customerId[is]" => (string)$customerID
));
$invoicesArr = [] // create empty array
foreach($result as $entry){
array_push($invoicesArr, $entry->invoice()); // foreach invoice, push it to array
}
echo json_encode($invoicesArr);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.