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 );基礎填充
<?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 arrayunset($arr); // This deletes the whole array ?>?
總結
以上是生活随笔為你收集整理的PHP构建数据结构填充数据的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 联合国儿童基金会官网怎么捐款
- 下一篇: 麦卡钱包贷款要交保证金是怎么回事