How can you display the actual image names instead of just the keys when using array_rand in PHP?

When using array_rand in PHP to retrieve random keys from an array of image names, you can display the actual image names by accessing the values corresponding to the keys returned by array_rand. You can do this by using the keys returned by array_rand to access the image names in the original array.

$imageNames = ['image1.jpg', 'image2.jpg', 'image3.jpg', 'image4.jpg', 'image5.jpg'];

$randomKeys = array_rand($imageNames, 2);

foreach ($randomKeys as $key) {
    echo $imageNames[$key] . "\n";
}