06c03-1.php

来自「介绍PHP5的给类型函数应用」· PHP 代码 · 共 40 行

PHP
40
字号
<?php// Define a few functions that echo different strings, based upon whether//  the number is divisible by a certain other number.function is_divisible_by_1($num) {    echo "<p>Of course $num is divisible by 1, everything is!</p>";}function is_divisible_by_2($num) {    if ($num % 2 == 0) {        echo "<p>$num is divisible by 2.  That means it is even.</p>";    }}function is_divisible_by_3($num) {    if ($num % 3 == 0) {        echo "<p>$num is divisible by 3.</p>";    }}function is_divisible_by_4($num) {    if ($num % 4 == 0) {        echo "<p>$num is divisible by 4.  It is double-even!</p>";    }}function is_divisible_by_5($num) {    if ($num % 5 == 0) {        echo "<p>$num is divisible by 5.  It ends in a 0 or a 5.</p>";    }}// Now, using a loop, going from 5 to 1, see what a given number (2000) is//  divisible by.  This will be true for all cases except for '3'for ($i = 5; $i > 0; $i--) {    // Check for divisibility by calling the appropriate function:    $var = 'is_divisible_by_' . $i;    $var(2000);}?>

⌨️ 快捷键说明

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