Hello I would like to have a code that displays randomly from an array a number and displays i开发者_如何学Ct. For example this code
<?php
$firstquarter = array(1 => 'January', 'February', 'March');
print_r($firstquarter);
?>
will return
Array
(
[1] => January
[2] => February
[3] => March
)
Instead of this, I would like to display on
A simple function called array_rand
example:
$selection = array_rand($my_array);
Documentation
Use rand()
$iIndex = rand(1, count($firstquarter));
echo $firstquarter[$iIndex];
This assumes you have an one indexed array with consecutive keys.
You need array_rand()
:
echo $firstquarter[array_rand($firstquarter)];
I'm not sure if this is what you want but here it goes:
echo mt_rand(intval(date('H') / 3) * 4, intval(date('H') / 3) * 5);
精彩评论