PHP Tutorials
How to randomize an array (Random Image, Random Text, Random Background, Random Redirect)
<?php
$myRandomArray = array(
'images/sun.jpg',
'images/sea.jpg',
'images/sand.jpg'
);
$myRandomOrder = $myRandomArray[array_rand($myRandomArray)];
echo '<img src=' . $myRandomOrder . ' width="500" height="200">';
?>
<?php
$myRandomArray = array(
'The sun shines in the sky.',
'A ship sails at sea.',
'I see footsteps in the sand.'
);
$myRandomOrder = $myRandomArray[array_rand($myRandomArray)];
echo $myRandomOrder
?>
<?php
$myRandomArray = array(
'images/sun.jpg',
'images/sea.jpg',
'images/sand.jpg'
);
$myRandomOrder = $myRandomArray[array_rand($myRandomArray)];
echo '<div style="width: 500px; height: 200px; padding: 10px; ';
echo 'background-image:url(' . $myRandomOrder . '); background-repeat: no-repeat;">';
echo 'My Text inside the layer';
echo '</div>';
?>
<?php
$myRandomSites = array("www.google.com",
"www.yahoo.com",
"www.bing.com")
;
$myRandomLink = $myRandomSites[array_rand($myRandomSites)];
header("location: http://$myRandomLink");
?>
<?php
$myRandomPages = array("my_first_page.php",
"my_second_page.php",
"my_third_page.php")
;
$myRandomLink = $myRandomPages[array_rand($myRandomPages)];
header("location: $myRandomLink");
?>
<?php
$myRandomStyleSheets = array(
'styles/white.css',
'styles/gray.css',
'styles/black.css'
);
$myRandomOrder = $myRandomStyleSheets[array_rand($myRandomStyleSheets)];
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Random CSS</title>
<link href="<?php echo $myRandomOrder ?>" rel="stylesheet" type="text/css" />
</head>
<body>
</body>
</html>