⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 02c05-1.php

📁 介绍PHP5的给类型函数应用
💻 PHP
字号:
<?php// Dice Simulatorfunction roll_dice($number, $sides, $values = false) {	// Loop as much as needed filling an array with the random die rolls.	$dice = array();	for ($i = 0; $i < $number; $i++) {		$dice[] = rand(1, $sides);	}		// If the optional 3rd parameter is set to true, return the dice array:	if ($values) {		return $dice;	} else {		// Otherwise, return the sum of the dice:		return array_sum($dice);	}}// Roll 3 six sided dice and echo their result (between 3 & 18)$roll_3d6 = roll_dice(3, 6);echo "<pre>Dice roll = {$roll_3d6}\n";// Roll a 100 sided die, 10 times, and echo all the values:$rm_stats = roll_dice(10, 100, true);print_r($rm_stats);echo '</pre>';?>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -