显示变量恰好是其他变量的3倍

时间:2012-11-26 20:16:59

标签: php function variables

$first = "Text 1"  
$second = "Text 2"  
$third = "Text 3"  
$fourth = "Text 4"  
$fifth = "Text 5"  

我想创建一个显示$ second和$ 4th的函数,其频率比其他变量高3倍。

怎么做?

1 个答案:

答案 0 :(得分:2)

$arr = array($first, $second, $second, $second, $third, $fourth, $fourth, $fourth, $fifth);
$elem = $arr[array_rand($arr)];

这将从数字变为值变量