Home  >  Article  >  Backend Development  >  Introduction to the method of converting php object to string

Introduction to the method of converting php object to string

藏色散人
藏色散人Original
2020-08-29 09:27:033513browse

How to convert php object to string: First create a PHP sample file; then convert an object object into a json string through the "json_encode($object);" method; and finally output the conversion result.

Introduction to the method of converting php object to string

Recommended: "PHP Video Tutorial"

PHP converts an object into a json string, Instead of converting to an array

json_encode parameter: http://php.net/manual/en/json.constants.php

Method:

$json_string = json_encode($object, JSON_FORCE_OBJECT);

Difference :

json_encode($object);
//结果:"[{"aa":"bb","cc":"dd"}]"
json_encode($object,JSON_FORCE_OBJECT);
//结果:"{"aa":"bb","cc":"dd"}"

The above is the detailed content of Introduction to the method of converting php object to string. For more information, please follow other related articles on the PHP Chinese website!

Statement:
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