MENU
Encoding
An object or array can be encoded to become a JSON string: json_encode($m [,$i1=0 [,$i2=512]]).$m can be an object, an array, scalar types or NULL. $i1 is a bitmask consisting of JSON_HEX_QUOT,
JSON_HEX_TAG, JSON_HEX_AMP, JSON_HEX_APOS, JSON_NUMERIC_CHECK, JSON_PRETTY_PRINT,
JSON_UNESCAPED_SLASHES, JSON_FORCE_OBJECT, JSON_UNESCAPED_UNICODE. $i2 is a positive integer representing the maximum depth.
The string representation of a JSON object may be in the form of an object, denoted by {}, or an array, denoted by []. Scalar values are encoded into the same, corresponding types.
RESETRUNFULL
RESETRUNFULL
<?php
$a = array('a' => 1, 'b' => 2, 'c' => 3, 'd' => 4, 'e' => 5);
echo json_encode($a),"<br/>";
$a = array('<cat>',"'dog'",'"cow"','&fish&', "\xc4\xa9");
echo json_encode($a, JSON_HEX_TAG | JSON_HEX_APOS | JSON_HEX_QUOT | JSON_HEX_AMP | JSON_UNESCAPED_UNICODE),"<br/>";
$a = array(array(1,2,3));
echo json_encode($a), "<br/>";
echo json_encode($a, JSON_FORCE_OBJECT), "<br/>";
$a = array("cat", "dog", "cow", "fish");
echo json_encode($a), "<br/>";
unset($a[0]);
echo json_encode($a), "<br/>";
class cl{
public $v1=1;
private $v2=2;
}
$a = new cl;
echo json_encode($a), "<br/>";
echo json_encode("abc"), "<br/>";
echo json_encode(3);
?>