我正在尝试将数据插入到codeigniter的highcharts中。 Highcharts希望数据成为这样的列表[313,985,5238,1237]。
但是从我的查询中,我从var_dump($ revenue)得到了这个结果:
array(14) {
[0]=> array(1) { ["data"]=> string(7) "2838475" }
[1]=> array(1) { ["data"]=> string(8) "136246.8" }
[2]=> array(1) { ["data"]=> string(7) "3406170" }
[3]=> array(1) { ["data"]=> string(9) "3655955.8" }
[4]=> array(1) { ["data"]=> string(7) "4132820" }
[5]=> array(1) { ["data"]=> string(7) "4087404" }
[6]=> array(1) { ["data"]=> string(9) "1271636.8" }
[7]=> array(1) { ["data"]=> string(8) "499571.6" }
[8]=> array(1) { ["data"]=> string(7) "9764354" }
[9]=> array(1) { ["data"]=> string(10) "713933.232" }
[10]=> array(1) { ["data"]=> string(10) "714614.466" }
[11]=> array(1) { ["data"]=> string(9) "2827121.1" }
[12]=> array(1) { ["data"]=> string(9) "1793916.2" }
[13]=> array(1) { ["data"]=> string(9) "2066409.8" }
}
$tanggal = array();
$revenue = array();
$top5 = array();
$data_top5 = $this->db->get_where('top_five_kfa', array('kfa' => 'Aceh', 'produk' => 'Fituno'))->result();
foreach ($data_top5 as $key => $value){
$tanggal[$key]['category'] = $value->tanggal;
$revenue[$key]['data'] = $value->revenue;
$top5[$key]['data'] = $value->top5;
我希望结果是这样的:
[2838475, 136246.8, 3406170, 3655955.8, 4132819.6, 4087404,
1271636.8, 499571.6, 9764354, 713933.232, 714614.466,
2827121.1, 1793916.2, 2066409.8]
任何建议如何?或任何参考?我被困了一个星期
答案 0 :(得分:0)
代替$revenue[$key]['data'] = $value->revenue;
使用 $revenue[] = $value->revenue;
echo json_encode($revenue);
将像您期望的那样提供数组列表。