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 6536901
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T10:33:10+00:00 2026-05-25T10:33:10+00:00

I have to iterate over an array and display its items. I have to

  • 0

I have to iterate over an array and display its items. I have to paginate it so I can render a paginator. The paginator structure is something like:

<div class='paginator'>
    <div class="page">
        <img src="path/to/picture"/>
        <img src="path/to/picture"/>
        <img src="path/to/picture"/>
        <img src="path/to/picture"/>
    </div>
    <div class="page">
        <img src="path/to/picture"/>
        <img src="path/to/picture"/>
        <img src="path/to/picture"/>
        <img src="path/to/picture"/>
    </div>
</div>

Finally, I have a PHP array with the paths. I want something like this:

echo "<div class='paginator'>";
for ($i = 0; $i < 3; $i++) {
   echo "<div class='page'>";
   for($j = 0; $j < 4; $j++) {
      echo "<img src='" . $arr[$i * $j] . "'/>"     
   }
   echo "</div>
}
echo "</div>";

But, it doesn’t work. I’m doing the loops incorrectly and I can’t figure out how they should be.

  • 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-05-25T10:33:10+00:00Added an answer on May 25, 2026 at 10:33 am

    Assuming yours is not just a simple sintax problem I think you need
    $arr[$i * 4 + $j]
    instead of
    $arr[$i * $j]
    Where “4” is the size of each row.
    Look at this example

    0  1  2  3 (4 elements in this row which starts from 0)
    4  5  6  7 (this row starts from 4)
    8  9 10 11 (this starts from 4 * 2)
    

    Each row starts with 4 (number of elements per row) multiplied for the number of the row (starting from 0). To iterate each element in the row you have to add the index of the element in the row ($j in your example) so: $index = $row_index * $elements_per_row + $column_index

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a 3D array in Python and I need to iterate over all
Is there an easy way to iterate over an associative array of this structure
I have an array and filled its values like that: $('#list input:checked').each(function() { deleteRecordIdsStr.push($(this).attr('name'));
I have a array of objects - something like this: [ {name : blar,
Say I have an $input array, that contains something like this : array 0
I have a checkbox list creating an array that I want to iterate over
Explanation I have a multidimensional array that is iterated over to created a categorized
I have a class and I want to be able to iterate over a
I have a const char arr[] parameter that I am trying to iterate over,
I have existing code that uses CMNewProfileSearch to find then iterate over the color

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.