php自定义数据结构,PHP构建数据结构填充数据

步骤:

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 );

基础填充

$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

?>

标签:arr,数据结构,填充,item,array,PHP,data,categories

来源: https://blog.csdn.net/fujian9544/article/details/99245735

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值