标签:
<?php
/**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"}
标签:
原文地址:http://www.cnblogs.com/liucong7708/p/5797518.html