Home > Backend Development > PHP Tutorial > PHP generates JSON

PHP generates JSON

不言
Release: 2023-03-29 16:48:01
Original
1531 people have browsed it

This article mainly introduces the generation of JSON by PHP, which has certain reference value. Now I share it with everyone. Friends in need can refer to it

<?php
$arr = array(
	&#39;id&#39;=>1,
	&#39;name&#39;=>&#39;andros230&#39;
);

$result = array(
	&#39;code&#39;=>&#39;200&#39;,
	&#39;msg&#39;=>&#39;成功&#39;,
	&#39;data&#39;=>$arr
		);
echo json_encode($result,JSON_UNESCAPED_UNICODE);

?>
Copy after login

Output: {"code":" 200","msg":"success","data":{"id":1,"name":"andros230"}}

Note: JSON_UNESCAPED_UNICODE requires PHP5 to solve Chinese garbled characters. Version 4 or above

Related recommendations:

php generates csv file

The above is the detailed content of PHP generates JSON. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template