note 110698 rejected from function.rand by googleguy
| From: | googleguy@php.net | Date: | Fri, 23 Nov 2012 20:12:30 +0000 |
| Subject: | note 110698 rejected from function.rand by googleguy | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-192125@lists.php.net to get a copy of this message | ||
Note Submitter: Anonymous
----
I need to get one out of random but I get 3 why?
<?php
$vowels = array("a", "e", "o", "u", "i",
"y");
$consonants = array("b", "c", "d", "v", "g",
"t", "f", "h", "k", "m", "n",
"w", "v", "z");
$numbers = array("1", "2", "3", "4", "5",
"6", "7", "8", "9", "0");
function randVowel()
{
global $vowels;
return $vowels[array_rand($vowels, 1)];
}
function randConsonant()
{
global $consonants;
return $consonants[array_rand($consonants, 1)];
}
function randNumber()
{
global $numbers;
return $numbers[array_rand($numbers, 1)];
}
function a1()
{
echo ("" . randConsonant() . "" . randVowel() . "" . randConsonant() .
"" . randVowel() . "" . randVowel() . "" . randConsonant() .
"" . randVowel() . "" . randConsonant() . "" . randVowel() .
"" . randNumber() . "<br>");
}
function a2()
{
echo ("" . randConsonant() . "" . randVowel() . "" . randConsonant() .
"" . randVowel() . "" . randVowel() . "" . randConsonant() .
"" . randVowel() . "" . randConsonant() . "" . randVowel() .
"" . randNumber() . "<br>");
}
function a3()
{
echo ("" . randConsonant() . "" . randVowel() . "" . randConsonant() .
"" . randVowel() . "" . randVowel() . "" . randConsonant() .
"" . randVowel() . "" . randConsonant() . "" . randVowel() .
"" . randNumber() . "<br>");
}
?>
<?php
echo rand(a1(),a2(),a3());
?>