note 127741 added to function.json-encode
| From: | elliseproduction at gmail dot com | Date: | Tue, 18 Oct 2022 13:31:48 +0000 |
| Subject: | note 127741 added to function.json-encode | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-219692@lists.php.net to get a copy of this message | ||
Notice that JSON_FORCE_OBJECT will convert all non-associative arrays to objects. This is not
necessarily a good solution for empty arrays.
If you want to convert only empty arrays to objects, simply convert them to empty object before use
json_encode function.
For example:
<?php
$foo=array(
'empty2object'=>(object)[],
'empty2array'=>[],
);
echo json_encode($foo); // {"empty2object":{},"empty2array":[]}
?>
----
Server IP: 45.112.84.4
Probable Submitter: 45.91.159.161 (proxied: 77.205.142.92)
----
Manual Page -- https://php.net/manual/en/function.json-encode.php
Edit -- https://main.php.net/note/edit/127741
Del: integrated -- https://main.php.net/note/delete/127741/integrated
Del: useless -- https://main.php.net/note/delete/127741/useless
Del: bad code -- https://main.php.net/note/delete/127741/bad+code
Del: spam -- https://main.php.net/note/delete/127741/spam
Del: non-english -- https://main.php.net/note/delete/127741/non-english
Del: in docs -- https://main.php.net/note/delete/127741/in+docs
Del: other reasons-- https://main.php.net/note/delete/127741
Reject -- https://main.php.net/note/reject/127741
Search -- https://main.php.net/manage/user-notes.php