Home >Backend Development >PHP Tutorial >Display one randomly in the array?

Display one randomly in the array?

WBOY
WBOYOriginal
2016-10-09 08:32:291302browse
<code> $arry = array('A','B','C','D');
$result = array_rand($arry,2);
foreach ($result as $val) 
{
echo $arry["$val"].""; 
}
</code>

Excuse me, this will randomly generate 2 sets of ABCD combinations, such as BC DC AB, etc.
But what I want to display is to display only one. Randomly display A or B or C or D from the array.
How to do this?
After I changed 2 to 1, it failed

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn