php_functions
Table of Contents
PHP Functions
- Nov 8, 2022
One
What is a function?
<?php $a = readLine("Your message: "); echo str_rot13($a) . "\n"; ?>
Two
Let's make functions to do stuff!
<?php echo add(2,2) . "\n"; echo sub(3,2) . "\n"; function add($a, $b) { return $a + $b; } function sub($a, $b) { return $a - $b; } function mul($a, $b) { return $a * $b; } function div($a, $b) { return $a / $b; } ?>
Three
<?php $n = 1; while ($n <= 10) { if (is_even($n)) { echo "{$n} is even.\n"; } else { echo "{$n} is odd.\n"; } $n = $n + 1; } function is_even($a) { return ($a % 2) == 0; }
php_functions.txt · Last modified: 2024/10/20 05:28 by appledog