PHP把数组转换为JSON字符串

/**PHP把数组转换为JSON字符串**/
$arr = [10,'Tom',true, '2015-10-15'];
//echo $arr;
echo json_encode($arr);//编码为JSON字符串

$arr = ['eid'=>10,'ename'=>'Tom','isMarried'=>true, 'birthday'=>'2015-10-15'];
//echo $arr;
echo json_encode($arr);//编码为JSON字符串

//结论:索引数组会被json_encode转换为JSON数组,关联数组会被json_encode转换为JSON对象

 ?>

结果如下

[10,"Tom",true,"2015-10-15"]

{"eid":10,"ename":"Tom","isMarried":true,"birthday":"2015-10-15"}

转载于:https://www.cnblogs.com/liucong7708/p/5797518.html

你可能感兴趣的:(php,json)