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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T07:16:45+00:00 2026-05-28T07:16:45+00:00

I have this code: $um = array(PHP, JAVA, MySQL) $a = count($um) for ($i

  • 0

I have this code:

$um = array("PHP", "JAVA", "MySQL")


 $a = count($um)

       for ($i = 0; $i < $a; $i++) {
            for ($x = $i + 1; $x <$a; $x++) {
                $arr1 [] = array($um[$i],$um[$x]);
            }
        }

This will output something like these combinations:

PHP[0] JAVA[1]
PHP[0] MySQL[2]
JAVA[1] MySQL[2]

Well, works without any problem.

But now, i want to change the output to something like:

PHP[0] JAVA[1]
JAVA[1] MySQL[2]
MySQL[2] PHP[0]

The logic will be the same for the three array elements or even 10, and so on.

Any idea about 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-05-28T07:16:46+00:00Added an answer on May 28, 2026 at 7:16 am

    Just use modular arithmetic: you want to pair indices (i,i+1), where the i+1 wraps around to 0 if it becomes too large.

    for ($i = 0; $i < $a; $i++) {
        echo $um[$i], ', ', $um[($i+1) % $a]
    }
    

    So for $a=3 this displays according to indices:

    0, 1
    1, 2
    2, 0 (since 3 % 3==0)
    

    Modulus Operator docs

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

Sidebar

Related Questions

I have this php code $jsonArray = array(); $sql = SELECT ID,CLIENT FROM PLD_SERVERS;
I need to move backwards through an array, so I have code like this:
I have this code: <?php ini_set('display_errors', true); error_reporting(E_ALL); include ../../../wp-load.php; $groups = array(); if
I have this code: <?php class Compare { private $questions; private $q_scores = array();
I have this code: $rows = array(); $res = mysql_query($someQuery); if(!mysql_errno()) while($row = mysql_fetch_assoc($res))
Right now, I have this code where $obj_arr maybe contain array and an object.
I have this block of code: users = Array.new users << User.find(:all, :conditions =>
I have an array created with this code: var widthRange = new Array(); widthRange[46]
I have code similar to this filtering entries in an Array of Objects: var
I have a HelloWorld.java located on my server, and I'd like to compile this

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.