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

  • Home
  • SEARCH
  • 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 8197897
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T05:50:12+00:00 2026-06-07T05:50:12+00:00

Within a for loop, i need to add some HTML that outputs only when

  • 0

Within a for loop, i need to add some HTML that outputs only when the loop is on a [(multiple of 3) minus 1].

For example, what i could do is:

for($i=0; $i<count($imagearray); $i++)
{
    if($i=="0" || $i=="2" || $i=="5" || $i=="8" || $i=="11")
    {
        echo 'string';
    }
}

but this isnt very elegant and extremely useless for big for loops, is there a proper way to do this?

  • 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-07T05:50:13+00:00Added an answer on June 7, 2026 at 5:50 am
    if ( $i==0 || ($i+1)%3 == 0 )
    {
        //do stuff
    }
    

    What this will do, is go to the next index, divide it by 3, and see if there is a remainder. If there is none, then that means that the current index is one less than a number that is divisible by 3

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

Sidebar

Related Questions

In my python script, I need to call within a for loop an executable,
Can you create a line of code, within a while-loop, that will create a
I have a variable within a loop that i am changing whenever i touch
I am using a foreach loop within PHP similar to this: foreach ($class->getAttributes() as
I have the following thats within a loop... echo <span class='srch-val'>.apply_filters( $value\n, $value).</span>; I
Why does an event handler never get called if it's added within a loop
I have an nsthread, a while loop within this one. It's getting objects from
Within a for loop, I'm using the following code to convert from one date
I was wondering if its possible to directly cast objects within a foreach loop.
I'd like to loop through the controls within a TabItem. my xaml is something

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.