The following two-dimensional array stores information (Author, ID, and Title) for a collection of books:
$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"));
I currently use a foreach loop to present this information in an HTML table:
<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>
This code generates the following table:
Author | Book ID | Title
AuthorA 1 titleA
AuthorB 1 titleA
AuthorC 2 titleB
AuthorC 3 titleC
AuthorD 3 titleC
Question: I would like to display the data in the following way:
Authors | Book ID | Title
AuthorA, Author B 1 titleA
AuthorC 2 titleB
AuthorC, Author D 3 titleC
How can I achieve this?
author,ID