0

I have 3 words: (book, help, air)

I want these 3 words to be displayed in different modes

Example :
book help air
book air help
help air book
air book help
....
sa eu
  • 23
  • 5

2 Answers2

0

First Set your word as array

$array = ['book', 'help', 'air'];

echo random_string_from_array( $array, 10);


// Function For string from words array randomization 
   
// $array is array of words, $n is number of times of randomization of words
    function random_string_from_array( $array, $n)
    {

        $my_str = '';
        
        for( $i == 1; $i <= $n; $i++ )
        {
            
          shuffle($array);
          
          $my_str .= implode(" ",$array);
          $my_str .= "<br>";
          
        }
    
        return $my_str;
    }
    
    
jiali
  • 616
  • 9
  • 20
  • Thanks - Can something be put instead of 10 to indicate n (non-duplicate)? – sa eu Aug 19 '21 at 04:53
  • you're welcome, if you want all of permutations your answer is here : (https://stackoverflow.com/questions/10222835/get-all-permutations-of-a-php-array) – jiali Aug 19 '21 at 15:55
0

You could use the function: array_rand https://www.php.net/manual/en/function.array-rand.php

$array = ['book', 'help', 'air'];

echo array_rand($array);
BGestel
  • 13
  • 3