Created
February 15, 2019 15:01
-
-
Save ifduyue/1b9c7c729462a9e3cb59dc8e88bf22f5 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$a = array('<foo>',"'bar'",'"baz"','&blong&', "\xc3\xa9", "中文"); | |
echo "Normal: ", json_encode($a), "\n"; | |
echo "Tags: ", json_encode($a, JSON_HEX_TAG), "\n"; | |
echo "Apos: ", json_encode($a, JSON_HEX_APOS), "\n"; | |
echo "Quot: ", json_encode($a, JSON_HEX_QUOT), "\n"; | |
echo "Amp: ", json_encode($a, JSON_HEX_AMP), "\n"; | |
echo "Unicode: ", json_encode($a, JSON_UNESCAPED_UNICODE), "\n"; | |
echo "All: ", json_encode($a, JSON_HEX_TAG | JSON_HEX_APOS | JSON_HEX_QUOT | JSON_HEX_AMP | JSON_UNESCAPED_UNICODE), "\n\n"; | |
$b = array(); | |
echo "Empty array output as array: ", json_encode($b), "\n"; | |
echo "Empty array output as object: ", json_encode($b, JSON_FORCE_OBJECT), "\n\n"; | |
$c = array(array(1,2,3)); | |
echo "Non-associative array output as array: ", json_encode($c), "\n"; | |
echo "Non-associative array output as object: ", json_encode($c, JSON_FORCE_OBJECT), "\n\n"; | |
$d = array('foo' => 'bar', 'baz' => 'long'); | |
echo "Associative array always output as object: ", json_encode($d), "\n"; | |
echo "Associative array always output as object: ", json_encode($d, JSON_FORCE_OBJECT), "\n\n"; | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment