展望輸出JSON的格式如下:建立JSON輸出多維數組
[{"Montgomery":[{"red":"12:34:56","yellow":"11:44:46","orange":"10:54:36","green":"9:24:26","purple":"8:14:16"}],"Suburban":[{"red":"12:34:56","yellow":"11:44:46","orange":"10:54:36","green":"9:24:26","purple":"8:14:16"}],"Shady Grove Adventist":[{"red":"12:34:56","yellow":"11:44:46","orange":"10:54:36","green":"9:24:26","purple":"8:14:16"}],"Holy Cross":[{"red":"12:34:56","yellow":"11:44:46","orange":"10:54:36","green":"9:24:26","purple":"8:14:16"}],"Washington Adventist":[{"red":"12:34:56","yellow":"11:44:46","orange":"10:54:36","green":"9:24:26","purple":"8:14:16"}]}]
我的代碼:
$xyz[] = array("Montgomery"=> array("Red" => "12:00", "Yellow" => "14:00"));
$xyz[] = array("Suburban"=> array("Yellow" => "16:00"));
echo '[' . json_encode($xyz) . ']';
我的結果:
[[{"Montgomery":{"Red":"12:00","Yellow":"14:00"}},{"Suburban":{"Yellow":"16:00"}}]]
完美,這正是我所期待的...... @wwwslinger:我想把它全部放在一個數組中,而不是創建一個類,但是出色的選項,謝謝你們兩個。 – BarclayVision