Using Arrays of Lambda Functions
<?php
$divisible = array(
1 => create_function('$n',
'echo "<p>$n is divisible by 1</p>";'),
2 => create_function('$n',
'if ($n % 2 == 0) {
echo "<p>$n is divisible by 2.</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.</p>"; }'),
5 => create_function('$n',
'if ($n % 5 == 0) { echo "<p>$n is divisible by 5.</p>"; }'),
);
foreach($divisible as $func) {
$func(2000);
}
?>
Related examples in the same category