PHP learning uses JSON_FORCE_OBJECT function to realize forced object transfer

little bottle
Release: 2023-04-06 07:56:02
forward
2833 people have browsed it

This article mainly talks about using the JSON_FORCE_OBJECT function to implement forced object transfer. Interested friends can learn about it!


$abc = array('a','b','c','d','e','f','g');
echo '
';
var_dump($abc);
echo json_encode($abc);
Copy after login

Output result: [When the array subscript is a numeric index,,,,,, and is continuous]


$abc = array('a',2=>'b',3=>'c',4=>'d',5=>'e',6=>'f',7=>'g');
echo '
';var_dump($abc);
echo json_encode($abc);
Copy after login

Output result: {When the array subscript is a numeric index,,,,,, and there is a break in the middle of the subscript} is parsed as an object


$abc = array('a','b','c','d','e','f','g');
echo '
';
var_dump($abc);
echo json_encode($abc,JSON_FORCE_OBJECT);
Copy after login

Output result:{ Use JSON_FORCE_OBJECT to cast to object }

Summary: Except for the continuous index array, everything else is parsed as object

Related tutorials: PHP video tutorial

The above is the detailed content of PHP learning uses JSON_FORCE_OBJECT function to realize forced object transfer. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:cnblogs.com
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 [email protected]
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!