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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T22:35:26+00:00 2026-05-23T22:35:26+00:00

I understand how str_shuffle() or shuffle works but I don’t know it in this

  • 0

I understand how str_shuffle() or shuffle works but I don’t know it in this case.

$word="tea";

I want to echo out all unique shuffling possibilities (tea, tae, eta, eat, ate, aet)

  • 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-23T22:35:27+00:00Added an answer on May 23, 2026 at 10:35 pm

    You need to produce all of the permutations of the string, either by iterating through the possibilities, or using a recursive method like this one below. Note that for a moderately sized array this will grow very large very quickly. For a word with unique characters, the number of possible permutations is n! where n is the length. For a six-letter word the array will have 720 entries! This method is not the most efficient, but depending on what you are trying to do, it should work ok.

    (Source: http://cogo.wordpress.com/2008/01/08/string-permutation-in-php/)

    function permute($str) {
        /* If we only have a single character, return it */
        if (strlen($str) < 2) {
            return array($str);
        }
    
        /* Initialize the return value */
        $permutations = array();
    
        /* Copy the string except for the first character */
        $tail = substr($str, 1);
    
        /* Loop through the permutations of the substring created above */
        foreach (permute($tail) as $permutation) {
            /* Get the length of the current permutation */
            $length = strlen($permutation);
    
            /* Loop through the permutation and insert the first character of the original
            string between the two parts and store it in the result array */
            for ($i = 0; $i <= $length; $i++) {
                $permutations[] = substr($permutation, 0, $i) . $str[0] . substr($permutation, $i);
            }
        }
    
        /* Return the result */
        return $permutations;
    }
    

    Note that this somewhat naive implementation will not handle duplicate letters correctly (for example, ‘seed’, having two e`s). As indicated in the source above, you can use the following code to eliminate duplicates if the word contains multiple of the same letter:

    $permutations = array_unique(permute($str));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I think I don't understand how the scope works in a switch case. Can
I understand this is an easy question but for some reason this just isn't
I understand what weak tables are. But I'd like to know where weak tables
can someone help me understand this because it's working in as3 but not so
I don't understand what this code is doing, I'm wanting to run a command
I don't understand what the %s and d% do in this C code: for
I understand why memory barriers are needed, but I don't get it in the
I don't understand why write like this: Class BlaBla(Of T as String) End Class
i really dont understand what happen here, its works on most of servers but
I understand I can create an enum like this: public enum MyEnum { ONE(1),

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.