目录
菜鸟教程:(变量作用域)https://www.runoob.com/php/php-variables.html
(函数)https://www.runoob.com/php/php-functions.html
(超级全局变量)https://www.runoob.com/php/php-superglobals.html
变量作用域
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Document</title> </head> <body> <?php // 函数及作用域 function add($num1, $num2) { return $num1 + $num2; } $sum = add(1, 3); echo $sum; // 静态作用于Static echo '<hr>'; function nextnum() { static $x = 1; // 输出结果:1 2 3 4 5 // $x = 1; // 如果不声明静态作用域,输出的结果都为1 echo $x; $x++; echo '<br/>'; } for ($i = 0; $i < 5; $i++) { // 调用5次nextnum函数的结果 nextnum(); } ?> </body> </html>
九九乘法口诀表
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Document</title> <style> tr, td { width: 80px; height: 30px; border: 1px solid rgb(255, 115, 0); color: rgb(255, 0, 21); text-align: center; font-size: 25px; font-weight: bold; background-color: rgb(166, 255, 0); } </style> </head> <body> <div style="width: 1000px;height:500px;margin:auto;"> <table style="width: 1000px;height:500px;"> <?php for ($i = 1; $i <= 9; $i++) { echo '<tr>'; for ($j = 1; $j <= $i; $j++) { echo '<td>' . "$j" . '*' . "$i" . '=' . $i * $j . '</td>'; } echo '</tr>'; } ?> </table> </div> </body> </html>