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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T02:09:48+00:00 2026-06-10T02:09:48+00:00

PHP novice here. I would like to ask for a bit of help with

  • 0

PHP novice here. I would like to ask for a bit of help with my nested loop. I think I’m close but I’m pretty sure what I’m missing is a switch or a break or both. I’ve messed with this for a while but I just cant get it right. Here is the code example.

<?php $items=array(thing01,thing02,thing03,thing04,thing05,thing06,thing07,thing08,thing09,thing10,thing11,thing12,thing13,thing14,thing15,thing16,thing17,thing18,thing19,thing20,thing21,thing22,thing23,thing24,thing25,thing26,thing27,thing28,thing29,thing30,thing31,thing32); ?>
<?php $array_count = count($items); ?>
<?php $item_count = 9; ?>
<?php $blk_Number = ceil( $array_count / $item_count); ?>
<?php echo "<h3>This list should contain " . $array_count . " items</h3>"; ?>
<ul>
<?php
for ($pas_Number = 1; $pas_Number <= $blk_Number; $pas_Number++) {print "<h3>Start of Block " . $pas_Number . " of 9         items</h3>";
for ($key_Number = 0; $key_Number < $item_count; $key_Number++){print "<li>" . $items[$key_Number] . "</li>"; }
{print "<h3>End of Block " . $pas_Number . " of 9 items</h3>"; }
}
; ?>
</ul>

This is giving me the output of:

This list should contain 32 items

Start of Block 1 of 9 items
thing01
thing02
thing03
thing04
thing05
thing06
thing07
thing08
thing09
End of Block 1 of 9 items
Start of Block 2 of 9 items
thing01
thing02
thing03
thing04
thing05
thing06
thing07
thing08
thing09
End of Block 2 of 9 items
Start of Block 3 of 9 items
thing01
thing02
thing03
thing04
thing05
thing06
thing07
thing08
thing09
End of Block 3 of 9 items
Start of Block 4 of 9 items
thing01
thing02
thing03
thing04
thing05
thing06
thing07
thing08
thing09
Start of Block 4 of 9 items
thing01
thing02
thing03
thing04
thing05
thing06
thing07
thing08
thing09
End of Block 4 of 9 items

As you can see the count of the Array elements is wrong. Block 2 should contain things 10-18, Block 3 should contain things 19-27, and Block 4 should contain the remaining 5 “things”. I apologize about all of the silly elements in the array, but I wanted to be able to clearly explain what I’m trying to do.

  • 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-10T02:09:49+00:00Added an answer on June 10, 2026 at 2:09 am

    I think you want to use array_chunk():

    foreach (array_chunk($items, 9) as $nr => $block) {
        echo "Block $nr\n";
        foreach ($block as $item) {
            echo "\t$item\n";
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am pretty familiar with jquery, but a novice at php, so excuse me
Yesterday I had a few question about OO and classes in PHP here but
I would like to write an adapter for PHP for the binary API of
I would like to have pretty URLs for my tagging system along with all
This only happens in some IE's. Here: http://animactions.ca/Animactions/volet_entreprise.php You may notice that when you
Php novice. 1.Is there anything wrong with this PHP & MySQL code? include_once db_login.php
I'm a PHP novice, and I recently found this database-free pagination script on a
I'm a novice when it comes to SQL and PHP, and I'm trying to
I am using PHP mail() to send daily notice emails. But I noticed that
I'm working on a new project, using Apache's mod_rewrite and PHP to get pretty

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.