0
我這樣打印多維數組和風格它
Array ( [6] => Array ( [id] => 6 [parent_id] => [text] => Top level comment [level] => 1 ) [1] => Array ( [id] => 1 [parent_id] => [text] => Top level comment [level] => 1 [children] => Array ( [2] => Array ( [id] => 2 [parent_id] => 1 [text] => Response to #1 ) [3] => Array ( [id] => 3 [parent_id] => 1 [text] => Response to #1 [children] => Array ( [4] => Array ( [id] => 4 [parent_id] => 3 [text] => Response to #3 ) ) ) [10] => Array ( [id] => 10 [parent_id] => 1 [text] => Response to #2 [children] => Array ( [11] => Array ( [id] => 11 [parent_id] => 10 [text] => Response to #10 [children] => Array ( [13] => Array ( [id] => 13 [parent_id] => 11 [text] => Response to #11 [children] => Array ( [14] => Array ( [id] => 14 [parent_id] => 13 [text] => Response to #13 ) ) ) ) ) [12] => Array ( [id] => 12 [parent_id] => 10 [text] => Response to #10 ) ) ) ) ) [5] => Array ( [id] => 5 [parent_id] => [text] => Top level comment [level] => 1 ) [9] => Array ( [id] => 9 [parent_id] => [text] => Top level comment [level] => 1 ) )
JSON
{"6":{"id":6,"parent_id":null,"text":"Top level comment","level":1},"1":{"id":1,"parent_id":null,"text":"Top level comment","level":1,"children":{"2":{"id":2,"parent_id":1,"text":"Response to #1"},"3":{"id":3,"parent_id":1,"text":"Response to #1","children":{"4":{"id":4,"parent_id":3,"text":"Response to #3"}}},"10":{"id":10,"parent_id":1,"text":"Response to #2","children":{"11":{"id":11,"parent_id":10,"text":"Response to #10","children":{"13":{"id":13,"parent_id":11,"text":"Response to #11","children":{"14":{"id":14,"parent_id":13,"text":"Response to #13"}}}}},"12":{"id":12,"parent_id":10,"text":"Response to #10"}}}}},"5":{"id":5,"parent_id":null,"text":"Top level comment","level":1},"9":{"id":9,"parent_id":null,"text":"Top level comment","level":1}}
什麼是呼應它的最簡單的方法和作風它陣列建立?說像reddit。我想在視圖文件中做樣式。
您對子級想分享您如何通過陣列倒是循環?我不知道該怎麼做,因爲孩子的數量= x。 – Martin 2013-03-02 11:57:53