Home>Article>Backend Development> php convert array to json format
php method to convert an array to json format: first create a PHP sample file; then pass "$arr = [10,'Tom',true, '2015-10-15'];echo json_encode( $arr);" statement can be converted.
The operating environment of this article: windows7 system, PHP7.1 version, DELL G3 computer
How does php convert an array into json format? ?
PHP converts an array into a JSON string
10,'ename'=>'Tom','isMarried'=>true, 'birthday'=>'2015-10-15']; //echo $arr; echo json_encode($arr);//编码为JSON字符串 //结论:索引数组会被json_encode转换为JSON数组,关联数组会被json_encode转换为JSON对象 ?>
The results are as follows
[10,"Tom",true,"2015-10-15"] {"eid":10,"ename":"Tom","isMarried":true,"birthday":"2015-10-15"}
Recommended learning: "PHP Video Tutorial"
The above is the detailed content of php convert array to json format. For more information, please follow other related articles on the PHP Chinese website!