以下二维数组存储书籍集合的信息(作者、ID 和标题):
$books = array(array('author'=>"AuthorA", 'ID'=>1, 'title'=>"titleA"),
array('author'=>"AuthorB", 'ID'=>1, 'title'=>"titleA"),
array('author'=>"AuthorC", 'ID'=>2, 'title'=>"titleB"),
array('author'=>"AuthorC", 'ID'=>3, 'title'=>"titleC"),
array('author'=>"AuthorD", 'ID'=>3, 'title'=>"titleC"));
我目前使用 foreach 循环在 HTML 表中显示此信息:
<table>
<tr>
<th>Author</th>
<th>Book ID</th>
<th>Title</th>
</tr>
<?php foreach ($books as $book): ?>
<tr>
<td><?php htmlout($book['author']); ?></td>
<td><?php htmlout($book['ID']); ?></td>
<td><?php htmlout($book['title']); ?></td>
</tr>
<?php endforeach; ?>
</table>
此代码生成下表:
Author | Book ID | Title
AuthorA 1 titleA
AuthorB 1 titleA
AuthorC 2 titleB
AuthorC 3 titleC
AuthorD 3 titleC
问题:我想以以下方式显示数据:
Authors | Book ID | Title
AuthorA, Author B 1 titleA
AuthorC 2 titleB
AuthorC, Author D 3 titleC
我怎样才能做到这一点?