Json in PHP

json_decode:

$json = ‘{“a”:1,”b”:2,”c”:3,”d”:4,”e”:5}’;
var_dump(json_decode($json)); //return as object
var_dump(json_decode($json, true)); //return as array

json_encode:

$arr = array(‘a’ => 1, ‘b’ => 2, ‘c’ => 3, ‘d’ => 4, ‘e’ => 5);
echo json_encode($arr);
Reference

Leave a Reply

Your email address will not be published. Required fields are marked *