It would be better to do something like this:
function PrintLinks($num) {
if ($num <= 0) {
return;
}
$links = array(
"<a href='http://www.glamourlingerie.co.nz/index.php?P=GL1007' border='0'><img src='http://www.glamourlingerie.co.nz/images/GL1007(b).jpg'></a>",
"<a href='http://www.glamourlingerie.co.nz/index.php?P=GL1018' border='0'><img src='http://www.glamourlingerie.co.nz/images/GL1018(a).jpg'></a>",
"<a href='http://www.glamourlingerie.co.nz/index.php?P=GL1013' border='0'><img src='http://www.glamourlingerie.co.nz/images/GL1013(a).jpg'></a>",
"<a href='http://www.glamourlingerie.co.nz/index.php?P=GL1013' border='0'><img src='http://www.glamourlingerie.co.nz/images/GL1013(a).jpg'></a>",
"<a href='http://www.glamourlingerie.co.nz/index.php?P=GL1013' border='0'><img src='http://www.glamourlingerie.co.nz/images/GL1013(a).jpg'></a>",
"<a href='http://www.glamourlingerie.co.nz/index.php?P=GL1013' border='0'><img src='http://www.glamourlingerie.co.nz/images/GL1013(a).jpg'></a>",
"<a href='http://www.glamourlingerie.co.nz/index.php?P=GL1013' border='0'><img src='http://www.glamourlingerie.co.nz/images/GL1013(a).jpg'></a>",
"<a href='http://www.glamourlingerie.co.nz/index.php?P=GL1013' border='0'><img src='http://www.glamourlingerie.co.nz/images/GL1013(a).jpg'></a>",
"<a href='http://www.glamourlingerie.co.nz/index.php?P=GL1013' border='0'><img src='http://www.glamourlingerie.co.nz/images/GL1013(a).jpg'></a>",
"<a href='http://www.glamourlingerie.co.nz/index.php?P=GL1013' border='0'><img src='http://www.glamourlingerie.co.nz/images/GL1013(a).jpg'></a>"
);
if ($num >= count($links)) {
foreach ($links as $link) {
echo $link;
}
} else {
$keys = array_rand($links, $num);
foreach ($keys as $key)
{
echo $links[$key];
}
}
}
After all, it does not make sense to limit the function to printing exactly 3 links. You might also consider returning the result array instead of printing it so that the caller can choose when to print it.
Also is there a way I can exclude the previous number from my random number?
My use of [man]array_rand/man does just that.