1 $arr = array("liming", "tom", "green");
 2 
 3 
 4 
 5 $arr2 = array(
 6         1 => "liming",
 7         2 => "tom",
 8         3 => "lucy",
 9         4 => "jim"
10     );
11     
12     echo json_encode($arr2)."\n";
13     
14            function returnJson($arr)
15         {
16             $str = "[";
17             $num = 0;
18             foreach ($arr as $k => $v)
19             {
20                 
21                 if($num == count($arr) - 1)
22                 {
23                     $str.="'".$v."'";
24                 }
25                 else
26                 {
27                     $str.="'".$v."',";
28                 }
29                 
30                 $num++;
31             }
32             $str .="]";
33             return $str;
34         }
35         
36         echo returnJson($arr2);

 

结果: