Deprecated: Function set_magic_quotes_runtime() is deprecated in /home/caffz123/hdd1/www/mud/AbyssalSwamp/index/include/common.inc.php on line 15

Warning: Cannot modify header information - headers already sent by (output started at /home/caffz123/hdd1/www/mud/AbyssalSwamp/index/include/common.inc.php:15) in /home/caffz123/hdd1/www/mud/AbyssalSwamp/index/include/global.func.php on line 170

Notice: Undefined index: include in /home/caffz123/hdd1/www/mud/AbyssalSwamp/index/include/common.inc.php on line 351

Warning: Cannot modify header information - headers already sent by (output started at /home/caffz123/hdd1/www/mud/AbyssalSwamp/index/include/common.inc.php:15) in /home/caffz123/hdd1/www/mud/AbyssalSwamp/index/include/global.func.php on line 170

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/caffz123/hdd1/www/mud/AbyssalSwamp/index/include/discuzcode.func.php on line 145

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/caffz123/hdd1/www/mud/AbyssalSwamp/index/include/discuzcode.func.php on line 245

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/caffz123/hdd1/www/mud/AbyssalSwamp/index/include/discuzcode.func.php on line 245

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/caffz123/hdd1/www/mud/AbyssalSwamp/index/include/discuzcode.func.php on line 245

Notice: Undefined index: visitedfid in /home/caffz123/hdd1/www/mud/AbyssalSwamp/index/include/forum.func.php on line 110

Notice: Undefined index: visitedfid in /home/caffz123/hdd1/www/mud/AbyssalSwamp/index/include/forum.func.php on line 122

Warning: Cannot modify header information - headers already sent by (output started at /home/caffz123/hdd1/www/mud/AbyssalSwamp/index/include/common.inc.php:15) in /home/caffz123/hdd1/www/mud/AbyssalSwamp/index/include/global.func.php on line 170

Notice: Undefined index: allowreply in /home/caffz123/hdd1/www/mud/AbyssalSwamp/index/viewthread.php on line 345

Notice: Undefined index: allowpost in /home/caffz123/hdd1/www/mud/AbyssalSwamp/index/viewthread.php on line 346
AbyssalSwamp 定制与源代码Technology Exchange - Case Board(C版) - 要实现PHP中变量随机代入内容,可以使用数组和rand()函数来达到目的。具体步骤如下: - www.caffz.com
AbyssalSwamp  ActivaUser
» Guest:  Register | Login | 冻结用户(激活) | Residents
Notice: Undefined index: links in /home/caffz123/hdd1/www/mud/AbyssalSwamp/index/forumdata/templates/1_header.tpl.php on line 59

RSS subscription to this AbyssalSwamp  

Previous thread Next thread
       
Title: 要实现PHP中变量随机代入内容,可以使用数组和rand()函数来达到目的。具体步骤如下:  
  This topic was added by com at 2024-11-22 11:53 移动 
 
sky999
天山茗客



UID 181291
Digest 2
Points 10
Posts 3867
码币MB 2624 Code
黄金 0 Catty
钻石 884 Pellet
Permissions 10
Register 2020-11-28
Status offline
要实现PHP中变量随机代入内容,可以使用数组和rand()函数来达到目的。具体步骤如下:

要实现PHP中变量随机代入内容,可以使用数组和rand()函数来达到目的。具体步骤如下:

1. 创建一个包含多个选项的数组,每个选项是你想要赋值给变量的内容。例如,我们创建一个颜色数组:

```
$colors = array("红色", "蓝色", "绿色", "黄色");
```

2. 使用rand()函数生成一个随机数,该随机数的范围应该是数组的下标范围。例如,如果我们有四个颜色选项,那么随机数的范围应该是0到3。

```
$random_index = rand(0, 3);
```

3. 使用随机数作为数组下标,从数组中选择一个选项并将其赋值给变量。

```
$random_color = $colors[$random_index];
echo "随机颜色是:". $random_color;
```

这样就可以实现变量随机代入内容的效果了。请注意,rand()函数在PHP 7.1版本之后已被弃用,建议使用更安全的random_int()函数。

Notice: Undefined variable: relatedkeywords in /home/caffz123/hdd1/www/mud/AbyssalSwamp/index/forumdata/templates/1_viewthread.tpl.php on line 208




CAFFZ.com
2023-6-6 17:56#1
View profile  Blog  Send a short message  Top
       


  Printable version | Recommend to a friend | Subscribe to topic | Favorite topic  


 


All times are GMT+8, and the current time is 2025-8-31 17:08 Clear informations ->sessions/cookies - Contact Us - CAFFZ - ZAKE
 


Warning: session_start(): Cannot send session cookie - headers already sent by (output started at /home/caffz123/hdd1/www/mud/AbyssalSwamp/index/include/common.inc.php:15) in /home/caffz123/hdd1/www/mud/AbyssalSwamp/index/urlcheck.php on line 2

Warning: session_start(): Cannot send session cache limiter - headers already sent (output started at /home/caffz123/hdd1/www/mud/AbyssalSwamp/index/include/common.inc.php:15) in /home/caffz123/hdd1/www/mud/AbyssalSwamp/index/urlcheck.php on line 2