<html> <head> <!-- Created by JohnKagga http://johnkagga.me --> <title> Functions </title> </head> <body> <!-- function without an argument --> <?php function sayName() { echo "My name is John Kagga <br>"; } sayName(); ?> <!-- function with an argument --> <?php function sayName2($name) { echo "My name is {$name} <br>"; } sayName2("John"); sayName2("Kagga"); ?> </body> </html>
echo "My name is John Kagga <br>"; } sayName(); ?> <!-- function with an argument --> <?php function sayName2($name) { echo "My name is {$name} <br>"; } sayName2("John"); sayName2("Kagga"); ?> <?php $name = "wang yang"; sayName2($name); // define a new function function sayName3($greeting, $target, $punct) { echo $greeting . ", " . $target . $punct . "!"; } sayName3("Good evening", $name, "!"); ?> <!-- returning a value from a function --> <br> <?php function addition($var1, $var2) { $sum = $var1 + $var2; return $sum; }