$first = "Text 1"
$second = "Text 2"
$third = "Text 3"
$fourth = "Text 4"
$fifth = "Text 5"
我想创建一个显示$ second和$ 4th的函数,其频率比其他变量高3倍。
怎么做?
答案 0 :(得分:2)
$arr = array($first, $second, $second, $second, $third, $fourth, $fourth, $fourth, $fifth);
$elem = $arr[array_rand($arr)];
这将从数字变为值变量