Are there any best practices for ensuring that array elements are not duplicated when outputting them in random order in PHP?

When outputting array elements in random order in PHP, one way to ensure that elements are not duplicated is to shuffle the array first and then loop through it to output the elements. This way, each element will only appear once in the output.

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

// Shuffle the array
shuffle($array);

// Output the elements in random order
foreach ($array as $element) {
    echo $element . " ";
}