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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T07:31:04+00:00 2026-06-03T07:31:04+00:00

I am using: $input = array(1, 2, 3, 4, 5); Now I want to

  • 0

I am using:

$input = array("1", "2", "3", "4", "5");

Now I want to start by printing the first value from the array (1) and another value for the remaining ones (2,3,4,5). Then next time, the print value will be 2 and further values (3,4,5,1). And so on, until the print value is 5 and the other values will be (1,2,3,4).

I am using a for-loop, but after the value 5, the loop should break…

What to do for this case….

out put should be: 1 the first time, then 2 then 3 then 4 then 5 then again 1 then continue on every refresh

  • 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-03T07:31:05+00:00Added an answer on June 3, 2026 at 7:31 am

    Does this do what you are looking for?

    <?php
    
    $input = array("1", "2", "3", "4", "5");
    $arr = array();
    
    foreach ($input as $item) {
        $i = array_shift($input);
        $arr[] = $input;
        $input[] = $i;
    }
    
    print_r($arr);
    

    OUTPUT

    Array
    (
        [0] => Array
            (
                [0] => 2
                [1] => 3
                [2] => 4
                [3] => 5
            )
    
        [1] => Array
            (
                [0] => 3
                [1] => 4
                [2] => 5
                [3] => 1
            )
    
        [2] => Array
            (
                [0] => 4
                [1] => 5
                [2] => 1
                [3] => 2
            )
    
        [3] => Array
            (
                [0] => 5
                [1] => 1
                [2] => 2
                [3] => 3
            )
    
        [4] => Array
            (
                [0] => 1
                [1] => 2
                [2] => 3
                [3] => 4
            )
    )
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to show some JavaScript array values in another document Input Boxes. Previously,
I want to read an integer array from console using boost::program_options. The length of
how to take user input in Array using Java? i.e we are not initializing
I'm reading from the standard input using the read() system call but there's a
I want to insert current time in database using mySQL function NOW() in Codeigniter's
I am using jquery-ui's autocomplete in my project. It works great. Now I want
I'm using C# to input and output multi 2d arrays into SQL database. The
I've been using the '-wap-input-format' CSS property to force to numeric input using *N.
I have some data (which users input using WYSIWYG editor). I have created a
I'm trying to sanitize/format some input using regex for a mixed latin/ideographic(chinese/japanse/korean) full text

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.