<html>
<body>
<?php
$images = array(
array('img' => 'image1.jpg', 'url' => 'http://example1.com', 'div' => 'class="d1"'),
array('img' => 'image2.jpg', 'url' => 'http://example2.com', 'div' => 'class="d2"'),
array('img' => 'image3.jpg', 'url' => 'http://example3.com', 'div' => 'class="d3"'),
array('img' => 'image4.jpg', 'url' => 'http://example4.com', 'div' => 'class="d4"'),
array('img' => 'image5.jpg', 'url' => 'http://example5.com', 'div' => 'class="d5"'),
array('img' => 'image6.jpg', 'url' => 'http://example6.com', 'div' => 'class="d6"')
);
// Selects 3 random array values and returns the key for each value
$randomkeys = array_rand($images, 3);
// Here we loop through the given index keys from the $images array.
// For each key we will then get the value from $images with the index $key
foreach ($randomkeys as $key) {
// I end with PHP_EOL (End of line) so the source code will look a bit prettier.
echo '<div class="1">' . PHP_EOL . '<a href="' . $images[$key]['url'] . '">' . PHP_EOL . '<div ' . $images[$key]['div'] . '>' . PHP_EOL . '<img src="' . $images[$key]['img'] . '">' . PHP_EOL . '</div>' . PHP_EOL . '</a></div>' . PHP_EOL;
}
?>
</body>
</html>