[help] php array, randomly combine output strings, refresh web page reassembly order, do not repeat

multiple keywords in an array are randomly combined for output. Refresh combination order is different
output string

$a=array ("red", "green", "blue", "yellow", "brown");
$random_keys=array_rand ($random_keys 4);
echo $a [$random_keys [0]]. "
";
echo $a [$random_keys [1]]. "
";
echo $a [$random_keys [2]];

this almost meets my requirements.
but the combined data will be repeated
should not be difficult, but I am a rookie.
give me a big brother to help

Php
Mar.12,2021

the easiest way

$a = ["red", "green", "blue", "yellow", "brown"];
shuffle($a);    // 
echo array_shift($a);    // array_pop
echo array_shift($a);
echo array_shift($a);

Note that this method changes the original array. If you don't want to change the original array, you need to add a judgment

.
$a = ["red", "green", "blue", "yellow", "brown"];
shuffle($a);
$has = [];    // 

// 
while (!in_array($a[0], $has) && count($has) <= 3) {
    $has[] = $a[0];
}

echo implode(',', $has); // ,

// 
shuffle($a);
// 
return implode('', array_slice($a, 3));
// :greenbrownred

feels that what you need is a shuffle algorithm, which is the shuffle function.

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b3a98a-2c23d.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b3a98a-2c23d.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?