Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7768541
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T15:56:24+00:00 2026-06-01T15:56:24+00:00

I am trying to build a simple page that will show book information, I

  • 0

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 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T15:56:26+00:00Added an answer on June 1, 2026 at 3:56 pm
    <?php
    
    $perRow=4;
    $i = 0;
    foreach($books as $book){
        if($i === 0){
            echo '<div class="row">';
        }
            echo '<div>';
            echo $book['name']. '<br>';
            echo $book['url']. '<br>';
            echo $book['big_photo']. '<br>';
            echo $book['small_photo']. '<br>';
            echo $book['bio']. '<br><br><br>';
            echo '</div>';
    
        if($i === $perRow){
            $i = 0;
            echo '</div>';
        }else{
            $i++;
        }
    }
    
    ?>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a simple image rotator script that I'm trying to build but I
I'm trying to build up a page that will show a progress bar until
I am trying to build a simple web page that has access to my
I am trying to build a simple Bookmarklet that will load some external Javascript
I'm trying to build a simple page that shows an image on the left
I am trying to build a simple FAQ page with answers that slideDown and
I'm trying to build a simple html page which include some text paragraph, during
When trying to build a simple test program that uses atomic operations, I get
I'm trying to write a simple google extension that will upon clicking ctrl+alt+x search
I'm trying to build an simple publishing tool in jquery. But i'm a bit

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.