PHP 数组有序 &嵌套 HTML 列表
我在项目中使用 jQuery nestedSortable 插件。当列表项被移动时,我序列化数组并将其保存到我的数据库中。我在从 PHP 数组重新创建 HTML 列表时遇到问题。大概是因为来晚了。 :)
我有以下 PHP 数组:
Array
(
[list_4] => root
[list_3] => 4
[list_1303966373] => 3
[list_1] => 1303966373
[list_5] => 1
[list_2] => 1
[list_6] => root
)
它应该创建一个类似于...的列表
<ol>
<li id='list_4'>value 4
<ol>
<li id='list_3'>value 3
<ol>
<li id='list_1303966373'>value 1303966373
<ol>
<li id='list_1'>value 1
<ol>
<li id='list_5'>value 5</li>
<li id='list_2'>value 2</li>
</ol>
</li>
</ol>
</li>
</ol>
</li>
</ol>
</li>
<li id='list_6'>value 6</li>
</ol>
(忽略这些值,它们只是用于显示。)
HTML 列表可以具有任意深度的嵌套列表。
我的大脑已经死了,我无法让它工作。有人有建议吗?我将永远欠你饼干。还有,一座城堡。
谢谢。 :)
I'm using the jQuery nestedSortable plugin in a project. When a list item is moved, I serialize the array and save it to my db. I'm having trouble recreating the HTML list from the PHP array. Probably because it's late. :)
I have the following PHP array:
Array
(
[list_4] => root
[list_3] => 4
[list_1303966373] => 3
[list_1] => 1303966373
[list_5] => 1
[list_2] => 1
[list_6] => root
)
It should make a list something like...
<ol>
<li id='list_4'>value 4
<ol>
<li id='list_3'>value 3
<ol>
<li id='list_1303966373'>value 1303966373
<ol>
<li id='list_1'>value 1
<ol>
<li id='list_5'>value 5</li>
<li id='list_2'>value 2</li>
</ol>
</li>
</ol>
</li>
</ol>
</li>
</ol>
</li>
<li id='list_6'>value 6</li>
</ol>
(Ignore the values, they're just there for show.)
The HTML list could have any depth of nested lists.
My brain is dead and I cannot get it to work. Anyone have a suggestion? I'll owe you cookies for eternity. Also, a castle.
Thanks. :)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
给你了(用你的样品测试没问题):
我想要我的饼干!呵呵。希望有帮助。
Here you have it (tested OK with your sample):
I want my cookie! Hehe. Hope it helps.