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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T13:00:47+00:00 2026-06-04T13:00:47+00:00

Im hoping someone can help me with a small problem! I have a php

  • 0

Im hoping someone can help me with a small problem!

I have a php while loop that loops 3 times.

Each time it loops I want an inner loop to output 2 incremental values per loop.

For example:

Loops the first time: Inner loop should output value 1, value 2

Loops the second time: Inner loop should output value 3, value 4

Loops the third time: Inner loop should output value 5, value 6

any ideas?

  • 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-04T13:00:49+00:00Added an answer on June 4, 2026 at 1:00 pm

    What about something like this :

    $in = 1;
    $out = 0;
    while (++$out <= 3) {
        echo "Outer loop $out : ";
        for ($i=0 ; $i<2 ; $i++) {
            echo "$in ";
            $in++;
        }
        echo "<br />";
    }
    

    Which gets me the following output :

    Outer loop 1 : 1 2
    Outer loop 2 : 3 4
    Outer loop 3 : 5 6
    

    Basically, here :

    • I’m using the $out variable to keep track of the number of times I’ve been through the outer loop — I only want to loop 3 times
    • I’m using the $i variable to control how many times the inner loop loops — two times, each time the outer while loops.
    • And I’m using the $in variable as a global counter, incremented by 1 every time the inner loop loops — this is what I want to output.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

got a small little problem I'm hoping someone can help me with. I have
We have an interesting problem that I was hoping someone could help to shed
Hoping someone can help with this. I have other VM's that dont have problems,
im hoping someone can help me quickly with a question i have. As site
I am hoping someone can help me with a question i have relating to
I'm hoping someone can help me as I've been stuck on this problem for
I am hoping someone can help me out with a quick question I have
This problem is very strange and I'm hoping someone can help me. For the
Alright, I am hoping someone can help me out. I apologize up front that
I have a question regarding the OnItemDataBound event and I'm hoping someone can help

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.