Home  >  Article  >  Backend Development  >  PHP randomly displays specified text (if elseif usage)

PHP randomly displays specified text (if elseif usage)

WBOY
WBOYOriginal
2016-07-25 08:55:391436browse
  1. /**
  2. * Randomly display the specified text
  3. * by bbs.it-home.org
  4. */
  5. function getRand() {
  6. $a=rand(1,5);
  7. if ($a==1) {
  8. echo "It’s sunny today ! ";
  9. }elseif ($a==2) {
  10. echo "It's sunny today";
  11. }elseif ($a==3) {
  12. echo "It's rainy today";
  13. }elseif ($a==4 ) {
  14. echo "Cloudy today";
  15. }elseif ($a==5) {
  16. echo "Meteor shower today";
  17. }
  18. }
  19. ?>
Copy code


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