I came across this problem when trying to decode
json into an array, for instance,
it works fine like this,
$year = 2012;
$month = 3;
$json = '{"year":'.$year.', "month":'.$month.'}';
$config = json_decode($json,true);
var_dump($config); // return array.
but if I set one of the variable to null
, for instance,
$year = 2012;
$month = null;
$json = '{"year":'.$year.', "month":'.$month.'}';
$config = json_decode($json,true);
var_dump($config); // return null
I am after this result,
array
'year' => int 2012
'month' => null
How can I return such result then?