我正在显示一个用 CakePHP 编写的应用程序的主题列表,如下所示:
<ul>
<?php foreach ($topics as $topic): ?>
<li>
<?php echo $topic['Topic']['title']; ?>
</li>
<?php endforeach; ?>
</ul>
我想做的是将它们显示为:
<h3>A</h3>
<ul>
<li>animals</li>
<li>anger</li>
<li>age</li>
</ul>
<h3>B</h3>
<ul>
<li>bat</li>
<li>bird</li>
</ul>
etc...
我该怎么做?请记住,我也可以有数字,例如 3d
大批
array(
(int) 0 => array(
'Topic' => array(
'id' => '1',
'title' => 'awesome'
),
'TopicPost' => array(
(int) 0 => array(
'id' => '1',
'topic_id' => '1',
'post_id' => '107'
)
)
),
(int) 1 => array(
'Topic' => array(
'id' => '2',
'title' => 'amazing'
),
'TopicPost' => array(
(int) 0 => array(
'id' => '2',
'topic_id' => '2',
'post_id' => '107'
)
)
),
(int) 2 => array(
'Topic' => array(
'id' => '3',
'title' => 'jazz'
),
'TopicPost' => array(
(int) 0 => array(
'id' => '3',
'topic_id' => '3',
'post_id' => '107'
)
)
)
)