是否有更优雅或更有效的方法从列表中随机选择字符串?
$case = rand(1,4);
switch ($case) {
case 1: $message = "Check this out.";
break;
case 2: $message = "Dig this.";
break;
case 3: $message = "Listen to this.";
break;
case 4: $message = "Try out this.";
break;
}
答案 0 :(得分:6)
$messages = array(
"Check this out.",
"Dig this.",
"Listen to this.",
"Try out this."
);
$message = $messages[array_rand($messages)];