Science, Tech, Math › Computer Science PHP Random Quote Add random quotes to your website with PHP Switch() Statement Share Flipboard Email Print PeopleImages/Getty Images Computer Science PHP Programming Tutorials MySQL Commands Perl Python Java Programming Javascript Programming Delphi Programming C & C++ Programming Ruby Programming Visual Basic View More By Angela Bradley Computer Science Expert B.A, History, Eastern Oregon University Angela Bradley is a web designer and programming expert with over 15 years of experience. An expert in iOS software design and development, she specializes in building technical hybrid platforms. our editorial process Angela Bradley Updated August 20, 2017 One way to add a random quote to your website is to use the PHP switch () statement. The switch statement compares one variable with many values and executes one piece of code depending on the value it equals. This allows you to prepare a list of quotations and then use the rand () function to select a number randomly that corresponds to one of the quotations. Using Switch to Display Random Quotes This example code demonstrates how to use switch () to display a random quote on your website. Each of the sample quotes is set to run when its number is chosen. By using rand () to choose a random number, one of the quotes is displayed at random. This example accommodates only six quotations, hence the rand (1,6) entry. To add more quotes, you change the rand () function to allow for higher numbers and then add in their corresponding cases in the code. If you want to include a random quote on your PHP web page, use include () to pull the quote from this file, like this: Cite this Article Format mla apa chicago Your Citation Bradley, Angela. "PHP Random Quote." ThoughtCo, Aug. 27, 2020, thoughtco.com/php-random-quote-2693820. Bradley, Angela. (2020, August 27). PHP Random Quote. Retrieved from https://www.thoughtco.com/php-random-quote-2693820 Bradley, Angela. "PHP Random Quote." ThoughtCo. https://www.thoughtco.com/php-random-quote-2693820 (accessed January 23, 2021). copy citation