ConFoo Montreal 2026: Call for Papers

Voting

: four plus two?
(Example: nine)

The Note You're Voting On

Anonymous
5 months ago
When JSON_OBJECT_AS_ARRAY is true, "json_decode($json)" is the same as "json_decode($json, false)" and return object actually.

<?php
$php_constants
= (get_defined_constants(true));
printf($php_constants['json']['JSON_OBJECT_AS_ARRAY'] . PHP_EOL);
$json = '{"a":1,"b":2,"c":3,"d":4,"e":5}';

$data = json_decode($json);
printf(is_array($data) . PHP_EOL);//false
var_dump($data);

$data = json_decode($json, false);
printf(is_array($data) . PHP_EOL);//false
var_dump($data);

$data = json_decode($json, true);
printf(is_array($data) . PHP_EOL);//true
var_dump($data);
?>

<< Back to user notes page

To Top