How to get data like this in controller in using codeigniter.
{
"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>";
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.