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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T11:28:04+00:00 2026-06-12T11:28:04+00:00

I am writing an application in PHP where users can enter two sets of

  • 0

I am writing an application in PHP where users can enter two sets of information and have every possible combination of the two sets printed out. The goal is to use it as a teaching tool for learning language by practicing different patterns of a question and answer.

For example, we may practice the question “Have you ever tried…?” plus one of four activities, such as bungee jumping, para sailing, skydiving, and scuba diving. There would also be four possible answers:

  1. Yes I have, and I enjoyed it.
  2. Yes I have, but I didn’t like it.
  3. No I haven’t, but I want to try it.
  4. No I haven’t, and I don’t want to try it.

The user would input the two sets of data, and the application would then print sheets of cards containing all possible combinations of the questions and answers. For example, card 1 would look like this:

  1. skydiving: Yes I have, and I enjoyed it.
  2. scuba diving: Yes I have, but I didn’t like it.
  3. parasailing: No I haven’t, but I want to try it.
  4. bungee jumping: No I haven’t, and I don’t want to try it.

The next card might then look like this:

  1. skydiving: Yes I have, but I didn’t like it.
  2. scuba diving: No I haven’t, but I want to try it.
  3. parasailing: No I haven’t, and I don’t want to try it.
  4. bungee jumping: Yes I have, and I liked it.

So as you can see, there are many different possible combinations. The idea would be that both lists would be of the same length to allow all of the possibilities to be printed out. It is also important that no question or answer gets used more than once on any card, and that two cards can be alike. What would be the best way to go about this? The actual input and output is not the problem–I’ve done similar things before. I just need the algorithm to produce the combinations.

EDIT: I guess what I’m really after is to keep the activities in the same order for each card, but have every possible combinations of answers. So what I really need is to be able to produce the following set of indexes for getting data out of the answers array. So I really want something more like this:

  • 0,1,2,3
  • 0,1,3,2
  • 0,2,1,3
  • 0,2,3,1
  • 0,3,1,2
  • 0,3,2,1
  • 1,0,2,3
  • 1,0,3,2
  • 1,2,0,3
  • 1,2,3,0

…and so on until all possible combinations have been produced.

  • 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-12T11:28:06+00:00Added an answer on June 12, 2026 at 11:28 am

    OK, with the new criteria, I think I understand a little better.

    Try recursion. My solution is messy as hell but I can walk you through it:

    $activities = array('a', 'b', 'c', 'd'); // Input all your activities as elements here.
    $responses = array(1, 2, 3, 4); // Input all your responses as elements here.
    
    // Recursive function outputCombos accepts both arrays (for eventual output).
    // $workingArray is the array of the current branch we're working with.
    function outputCombos ($activities, $responses, $workingArray) {
        // Once the working array has been loaded to the maximum amt, print everything out.
        if (count($workingArray) == count($responses)) {
            echo "Combo\n";
            for ($x = 0; $x < count($activities); $x++) {
                echo $activities[$x].'::'.$workingArray[$x]."\n";
            }
        // If the working array isn't full, add an element that isn't currently in the working array, and recursively run the function again.
        } else {
            foreach ($responses as $response) {
                // Iterate through list of all possible responses, add it into a new working array and run the function if the response hasn't been used in this working array.
                if (!in_array($response, $workingArray)) {
                    $newArray = $workingArray;
                    $newArray[] = $response;
                    outputCombos($activities, $responses, $newArray);
                }
            }
        }
    }
    
    foreach ($responses as $response) {
        echo '<pre>';
        // Start each branch of tree with unique response (should be 4 in this case).
        outputCombos($activities, $responses, array($response));
        echo '</pre>';
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In a PHP application I am writing, I would like to have users enter
I am writing a web application in php where users can upload their own
I'm writing a web application (PHP) for my friend and have decided to use
I am writing a PHP application that will have the ability to edit settings
I am writing a PHP application that's supposed to allow users to add certain
I'm writing an application in PHP, and I need to replace any word between
I'm writing a php application and was wondering if it's a bad idea to
I am writing a new application in PHP which will be released to the
I'm currently writing a PHP application and drivers (classes) for the database engines. I
Background: Experienced PHP developer with a mostly *nix background. I'm writing a PHP application

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.