User-defined functions CODE
Function that does something
function printGreeting() {
	print "Prints: Hello world!\n";
}
printGreeting();
Function that returns something
function returnGreeting() {
	return "Returns: Hello world!\n";
}
echo returnGreeting();
Parameterized function that doubles the number
function doubleMe($number) {
	$result = "$number times 2 is: " . $number * 2 . "\n";
	return $result;
}
echo doubleMe(4);
Function calculates the sum of two numbers
function add($num1, $num2) {
	$sum = $num1 + $num2;
	$result = "Sum of $num1 and $num2 is: $sum";
	return $result;
}
echo add(4, 5);
by Valeri Tandilashvili
2 years ago
PHP
functions
2
Pro tip: use ```triple backticks around text``` to write in code fences