What potential issues can arise when using array_rand() within a while() loop in PHP?

When using array_rand() within a while() loop in PHP, the potential issue that can arise is that the same random element may be selected multiple times, leading to duplication. To solve this issue, you can remove the selected element from the array within each iteration of the loop.

$array = [1, 2, 3, 4, 5];
$selected = [];

while(count($selected) < count($array)){
    $randomKey = array_rand($array);
    $randomValue = $array[$randomKey];
    
    unset($array[$randomKey]);
    $selected[] = $randomValue;
    
    // Your code to use $randomValue goes here
}