2
當試圖decode
JSON爲陣列,比如我碰到這個問題來了,json_decode返回NULL當值爲空
它工作正常這個樣子,
$year = 2012;
$month = 3;
$json = '{"year":'.$year.', "month":'.$month.'}';
$config = json_decode($json,true);
var_dump($config); // return array.
但如果我設置變量之一null
,例如,
$year = 2012;
$month = null;
$json = '{"year":'.$year.', "month":'.$month.'}';
$config = json_decode($json,true);
var_dump($config); // return null
我這個結果後,
array
'year' => int 2012
'month' => null
我該如何返回這樣的結果呢?
得到它。感謝你的回答! – laukok 2012-03-28 18:13:55