php 随机_PHP随机报价

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()从此文件中提取引号,如下所示:

翻译自: https://www.thoughtco.com/php-random-quote-2693820

php 随机

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值