06c05-1.php

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

PHP
27
字号
<?php// Define a few functions that echo different strings, based upon whether//  the number is divisible by a certain other number.$divisible = array(    1 => create_function('$n',         'echo "<p>Of course $n is divisible by 1, everything is!</p>";'),    2 => create_function('$n',        'if ($n % 2 == 0) {             echo "<p>$n is divisible by 2.  It is even.</p>"; }'),    3 => create_function('$n',        'if ($n % 3 == 0) {             echo "<p>$n is divisible by 3.</p>"; }'),    4 => create_function('$n',        'if ($n % 4 == 0) {             echo "<p>$n is divisible by 4.  It is double-even!</p>"; }'),    5 => create_function('$n',        'if ($n % 5 == 0) { echo "<p>$n is divisible by 5.              It therefore ends in a 0 or a 5.</p>"; }'),    );// Now loop through these functions, calling them all on the number 2000//  They will be true for all cases except for '3'foreach($divisible as $func) {    $func(2000);}?>

⌨️ 快捷键说明

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