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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T21:16:23+00:00 2026-06-01T21:16:23+00:00

I am using array_chunk but i want to be able to echo something different

  • 0

I am using array_chunk but i want to be able to echo something different for the first array in the chunk.
Not sure on how to do this and could not find anything. Any help/guidance would be appreciated.

Say i use:

     foreach (array_chunk($entries, 4) as $row) { 

    if (the array chunk is the first) {echo '<div class="cn_page" style="display:block;">';}
    else {echo '<div class="cn_page">';} 

}

Full code below:

echo ‘

<div id="cn_preview" class="cn_preview">';

foreach($entries as $entry){
echo '<div class="cn_content" style="top:5px;">
      <img src="newsslider/images/polaroidphotobar.jpg" alt=""/>
      <h1>'.$entry->title.'</h1>
      <span class="cn_date">'.$entry->modified.'</span>
      <span class="cn_category"></span>
      <p>'.$entry->text.'</p>
      <a href="" target="_blank" class="cn_more">Read more</a>
      </div>';     
}
echo '</div>';


echo '<div id="cn_list" class="cn_list">';

foreach (array_chunk($entries, 4) as $row) { 

if (the array chunk is the first) {echo '<div class="cn_page" style="display:block;">';}
else {echo '<div class="cn_page">';}

foreach ($row as $entry) {
$i++;

if ($i == 1){echo '<div class="cn_item selected">';}
else {echo '<div class="cn_item">';}

echo '<h2>'.$entry->title.'</h2>
<p>'.$entry->text.'</p>
</div>';
echo '</div>'; 

}
echo '</div>'; 
}
echo'<div class="cn_nav">
            <a id="cn_prev" class="cn_prev disabled"></a>
            <a id="cn_next" class="cn_next"></a>
</div>
</div>
</div>';
  • 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-01T21:16:25+00:00Added an answer on June 1, 2026 at 9:16 pm

    That would be:

    foreach (array_chunk($entries, 4) as $key => $row) { 
        if ($key == 0) {
            echo '<div class="cn_page" style="display:block;">';
        } else {
            echo '<div class="cn_page">';
        } 
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to be able to map a path to a different domain but
I'm interested in speed, not good looking code, that is why I'm using array
I'm using this (simplified) chunk of code to extract a set of tables from
I'm writing a small byte array of two bytes using something like the following:
I'm not sure if the title is very clear, but basically what I have
So I must be doing something wrong here, just not sure what it is
After using array_unique , an array without the duplicate values is removed. However, it
How would I convert the following to a VB.NET predicate using Array.Find? Private Function
I need to create an array of arrays. I have been using array_map(null,$a,$b,$c) to
Is there any speed/space/general performance gains in using array based implementation of a binary

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.