PHP 数组转json格式,key的保存问题

 1 <?php
 2 $arr = [
 3     2,
 4     3,
 5 ];
 6 echo print_r($arr,true);
 7 echo json_encode($arr);
 8 echo "\n\n";
 9 
10 $arr = [
11     0 => 2,
12     1 => 3,
13 ];
14 echo print_r($arr,true);
15 echo json_encode($arr);
16 echo "\n\n";
17 
18 $arr = [
19     0 => 2,
20     2 => 3,
21 ];
22 echo print_r($arr,true);
23 echo json_encode($arr);
24 echo "\n\n";
25 
26 $arr = [
27     1 => 2,
28     2 => 3,
29 ];
30 echo print_r($arr,true);
31 echo json_encode($arr);
32 echo "\n\n";
33 
34 $arr = [
35     '0' => 2,
36     '1' => 1,
37 ];
38 echo print_r($arr,true);
39 echo json_encode($arr);
40 echo "\n\n";
41 
42 $arr = [
43     '1' => 2,
44     '2' => 1,
45 ];
46 echo print_r($arr,true);
47 echo json_encode($arr);
48 echo "\n\n";
49 
50 
51 $arr = [
52     '0' => 2,
53     '2' => 1,
54 ];
55 echo print_r($arr,true);
56 echo json_encode($arr);
57 echo "\n\n";

 

posted @ 2017-06-12 12:16  GoodByeZ  阅读(1552)  评论(0编辑  收藏  举报