Home>Article>Backend Development> PHP learning uses JSON_FORCE_OBJECT function to realize forced object transfer
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 '';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('a','b','c','d','e','f','g'); echo ''; var_dump($abc); echo json_encode($abc,JSON_FORCE_OBJECT);Output result:{ UseJSON_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!