开发者

Cleaner PHP Random Text

开发者 https://www.devze.com 2022-12-13 09:53 出处:网络
Playing around with generating text randomly with开发者_StackOverflow each page refresh using php. Is there a cleaner way to approach this? Also, can this be done with jquery?

Playing around with generating text randomly with开发者_StackOverflow each page refresh using php. Is there a cleaner way to approach this? Also, can this be done with jquery?

<?php
$random_text = array("Random Text 1",
                "Random Text 2",
                "Random Text 3",
                "Random Text 4",
                "Random Text 5");
srand(time());
$sizeof = count($random_text);
$random = (rand()%$sizeof);
print("$random_text[$random]");
?>


Use array_rand()

$random_text = array("Random Text 1",
                "Random Text 2",
                "Random Text 3",
                "Random Text 4",
                "Random Text 5");

print_r($random_text[array_rand($random_text)]);
0

精彩评论

暂无评论...
验证码 换一张
取 消