[英]Json array result in codeigniter
How to get data like this in controller in using codeigniter.如何使用 codeigniter 在 controller 中获取这样的数据。
{
"price": [
[
1483275269000,
972.948
],
[
1483361668000,
1025.88
]
]
}
I've tried我试过了
$invoices = $this->invoice_model->getAllData2(logged('company_id'));
$response['price'] = $invoices;
echo json_encode($response,TRUE);
I only get like this我只会这样
{"price":[{"date_issued":"2021-03-01","grand_total":"972.948"},{"date_issued":"2021-03-12","grand_total":"1025.88"}]}
Can you help me with this guys?你能帮我解决这些问题吗? I need it so bad.我太需要了Thank you in advance guys.提前谢谢你们。
Your data needs just further processing to return it the way you like您的数据只需要进一步处理即可以您喜欢的方式返回
$temp = [];
foreach($invoices as $key1 => $value1) {
foreach($value1 as $key2 => $value2) {
switch($key2) {
case 'date_issued':
$temp[$key1][] = strtotime($value2);
break;
case 'grand_total':
$temp[$key1][] = floatval($value2);
break;
default:
break;
}
}
}
$response['price'] = $temp;
echo json_encode($response,TRUE);
You can try pretty print like this,你可以试试这样漂亮的打印,
echo "<pre>".json_encode($response,TRUE)."</pre>";
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.