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.
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!