版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
步骤:
1.先进行构建数据结构
2.进行一步步的添加数据
注释:[]表示的就是内容 前面键值的内容
// 构建数据结构
$data = [
'categories' => [],
'series' => [
[
'name' => '日分享',
'data' => []
]
]
];
// 进行对数据结构进行添加数据
if( $list ){
foreach( $list as $_item ){
//就是向categories里面进行添加数据
$data['categories'][] = $_item['date'];
// 就是想data里面添加数据
// 为什么会有一个0呢 因为二维数组啊 加个0要指代一下啊!!!
// 如果直接没有【】的话 就不用【0】了
$data['series'][0]['data'][] = $_item['total_shared_count'];
}
}
return $this->renderJSON( $data );
基础填充
<?php
$arr = array(5 => 1, 12 => 2);
$arr[] = 56; // This is the same as $arr[13] = 56;
// at this point of the script
$arr["x"] = 42; // This adds a new element to
// the array with key "x"
unset($arr[5]); // This removes the element from the array
unset($arr); // This deletes the whole array
?>