$arr = array("liming", "tom", "green"); $arr2 = array(
1 => "liming",
2 => "tom",
3 => "lucy",
4 => "jim"
); echo json_encode($arr2)."\n"; function returnJson($arr)
{
$str = "[";
$num = 0;
foreach ($arr as $k => $v)
{ if($num == count($arr) - 1)
{
$str.="'".$v."'";
}
else
{
$str.="'".$v."',";
} $num++;
}
$str .="]";
return $str;
} echo returnJson($arr2);
结果: