What is the purpose of using array_rand() in PHP and how does it differ from shuffle()?
The purpose of using array_rand() in PHP is to randomly select one or more keys from an array. This function returns the key (or keys) of the randomly selected element(s) without changing the original array. On the other hand, shuffle() is used to randomly shuffle the elements of an array in place, changing the order of the elements within the array.
// Using array_rand() to randomly select a key from an array
$array = [1, 2, 3, 4, 5];
$randomKey = array_rand($array);
echo "Randomly selected key: " . $randomKey;
// Using shuffle() to randomly shuffle the elements of an array
shuffle($array);
print_r($array);