php 随机
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.
向您的网站添加随机报价的一种方法是使用PHP switch()语句。 switch语句将一个变量与多个值进行比较,并根据它等于的值执行一段代码。 这使您可以准备一个报价单列表,然后使用rand()函数随机选择一个与报价单相对应的数字。
使用开关显示随机报价 ( 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.
此示例代码演示了如何使用switch()在您的网站上显示随机报价。 选择每个样本报价时,将其编号设置为运行。 通过使用rand()选择一个随机数 ,引号之一会随机显示。 本示例仅容纳六个引号,因此是rand(1,6)条目。
To add more quotes, you change the rand () function to allow for higher numbers and then add in their corresponding cases in the code.
要添加更多的引号,可以更改rand()函数以允许使用更大的数字,然后在代码中添加其相应的大小写。
If you want to include a random quote on your PHP web page, use include () to pull the quote from this file, like this:
如果要在PHP网页上包含随机引号,请使用include()从此文件中提取引号,如下所示:
php 随机