I am trying to build a simple page that will show book information, I was going to store it all in a database but I have decided it would be better to just build a multidimensional array and store it in that.
There is just 4 “books” in the example below but there could be up to 100 eventually.
I need help iterating over this array and showing each item in an HTML <li> but I need to only show 4 in a row then start a new row. Can someone show me how to accomplish this?
<?php
$books = array(
1 => array(
'name' => 'book 1 name here',
'url' => '',
'big_photo' => 'big photo of book 1',
'small_photo' => 'small photo of book 1',
'bio' => 'short bio 1'
),
2 => array(
'name' => 'book 2 name here',
'url' => '',
'big_photo' => 'big photo of book 2',
'small_photo' => 'small photo of book 2',
'bio' => 'short bio 2'
),
3 => array(
'name' => 'book 3 name here',
'url' => '',
'big_photo' => 'big photo of book 3',
'small_photo' => 'small photo of book 3',
'bio' => 'short bio 3'
),
4 => array(
'name' => 'book 4 name here',
'url' => '',
'big_photo' => 'big photo of book 4',
'small_photo' => 'small photo of book 4',
'bio' => 'short bio 4'
)
);
echo $books["1"]["small_photo"];
?>
Example output
<ul>
<li>books data</li>
<li>books data</li>
<li>books data</li>
<li class="lastRow">books data</li>
<li>books data</li>
<li>books data</li>
<li>books data</li>
<li class="lastRow">books data</li>
<li>books data</li>
<li>books data</li>
<li>books data</li>
<li class="lastRow">books data</li>
</ul>
1 Answer