Is using array_unique and array_rand the most efficient way to select random entries from an array in PHP?

When selecting random entries from an array in PHP, using array_unique and array_rand together may not be the most efficient way. Instead, a more direct approach would be to shuffle the array and then select a specific number of elements from the shuffled array. This method ensures that each element has an equal chance of being selected.

// Original array
$array = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];

// Shuffle the array
shuffle($array);

// Select a specific number of random entries (e.g., 3)
$randomEntries = array_slice($array, 0, 3);

// Output the random entries
print_r($randomEntries);