我已经为 jquery 序列化了字符串:
[{"id":1},
{"id":2,"children":[{"id":3}]},
{"id":4,"children":[{"id":5,"children":[{"id":6,"children":[{"id":7}]}]}]},
{"id":8},{"id":9},{"id":10}
]
我想在 PHP 中解释这个以获得类似的东西:
$menu = array(
array( 'name' => 'Item 1', 'id' => '1' ,'children' => '0'),
array( 'name' => 'Item 2', 'id' => '2' ,'children' => '0'),
array( 'name' => 'Item 3', 'id' => '3' ,'children' => '2'),
array( 'name' => 'Item 4', 'id' => '4' ,'children' => '0'),
array( 'name' => 'Item 5', 'id' => '5' ,'children' => '4'),
array( 'name' => 'Item 6', 'id' => '6' ,'children' => '5'),
array( 'name' => 'Item 7', 'id' => '7' ,'children' => '6'),
array( 'name' => 'Item 8', 'id' => '8' ,'children' => '0'),
array( 'name' => 'Item 9', 'id' => '9' ,'children' => '0'),
array( 'name' => 'Item 10', 'id' => '10','children' => '0'),
);
(当children == 0时,则该项目为根类别。)
非常感谢您的建议。卡利斯。