...

View Full Version : array random



helen11
11-20-2011, 08:03 PM
Hi I have created an array for random allocation of holiday months

<?php
$months = array("Feburary", "April", "June");
?>

does anyone know how i could randomly allocate one of the 3 specified months in every year over the period of 9 years

Adee
11-20-2011, 08:34 PM
<?php
$months = array("Feburary", "April", "June");



for($i=0;$i<108;$i++)
{
echo $i . ": " . $months[rand(0,(count($months)-1))] . "<br />";
}


?>

helen11
11-20-2011, 09:02 PM
How can i print the randomly allocated month in each year

Adee
11-20-2011, 09:18 PM
How can i print the randomly allocated month in each year

well.. there are 108 months in 12 years so every 12 numbers it echos is a year..

Adee
11-20-2011, 09:22 PM
This will return 9 arrays all consisting of 12 random months from your array



$months = array("Feburary", "April", "June");


$years = array();
for($i=1;$i<13;$i++)
{
for($x=1;$x<10;$x++)
{
$years[$x][] = $months[rand(0,(count($months)-1))];
}

}

var_dump($years);



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum