写复杂的json方法
<?php for($j=0; $j< 30; $j++) { $Axis[$j] = "a"; } $data['xAxis']= $Axis; for($i=0; $i < 30 ; $i++) { $D['data'][$i]= 3000+ $i * $i; } $data['money'][0] = $D; for($i=0; $i < 30 ; $i++) { $D['data'][$i]= 2000+ ($i-1)*($i+1); } $data['money'][1] = $D; $data= json_encode($data); // json_encode ()对变量进行 JSON 编码 echo $data; ?>
echo的结果是:
{"xAxis":["a","a","a","a","a","a","a","a","a","a","a","a","a","a","a","a","a","a","a","a","a","a","a","a","a","a","a","a","a","a"],"money":[{"data":[3000,3001,3004,3009,3016,3025,3036,3049,3064,3081,3100,3121,3144,3169,3196,3225,3256,3289,3324,3361,3400,3441,3484,3529,3576,3625,3676,3729,3784,3841]},{"data":[1999,2000,2003,2008,2015,2024,2035,2048,2063,2080,2099,2120,2143,2168,2195,2224,2255,2288,2323,2360,2399,2440,2483,2528,2575,2624,2675,2728,2783,2840]}]}