Home  >  Article  >  Backend Development  >  PHP learning uses JSON_FORCE_OBJECT function to realize forced object transfer

PHP learning uses JSON_FORCE_OBJECT function to realize forced object transfer

little bottle
little bottleforward
2019-04-20 17:41:262992browse

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 'e03b848252eb9375d56be284e690e873';
var_dump($abc);
echo json_encode($abc);

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 &#39;<pre class="brush:php;toolbar:false">&#39;;var_dump($abc);
echo json_encode($abc);

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(&#39;a&#39;,&#39;b&#39;,&#39;c&#39;,&#39;d&#39;,&#39;e&#39;,&#39;f&#39;,&#39;g&#39;);
echo &#39;<pre class="brush:php;toolbar:false">&#39;;
var_dump($abc);
echo json_encode($abc,JSON_FORCE_OBJECT);

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!

Statement:
This article is reproduced at:cnblogs.com. If there is any infringement, please contact admin@php.cn delete