HTML Tutorial
PHP Function
The php function is similar to other functions from other programming languages.
The function is a pice of programming code which takes one or more inputs as parameters and does some processing and returns a value.
A user-defined function declaration starts with the word function:
Syntax:
function functionName() {
code to be executed;
}
Creating PHP Function - how? - example
In the example below, we have created a function named "WriteMyMessage()".
The function outputs "This is your first PHP function. Have a nice day".
To call the function, just write its name:
Example 1: Using implode() to go from an Array to a String
<?php
/* Defining a PHP Function */
function WriteMyMessage() {
echo "This is your first PHP function.
Have a nice day";
}
/* Calling a PHP Function */
WriteMyMessage();
?>
/* Defining a PHP Function */
function WriteMyMessage() {
echo "This is your first PHP function.
Have a nice day";
}
/* Calling a PHP Function */
WriteMyMessage();
?>
PHP cod above will display this result -
Note: There are two parts of function which should be clear to you −
Creating a PHP Function
Calling a PHP Function
Creating a PHP Function
Calling a PHP Function
PHP Functions with Parameters - How to create
PHP gives you the option to pass parameters into a function. You can pass as many parameters as you can.
The following example has three integer parameters, adds them and then prints them together.
Example 2:
The PHP cod above will display this result -
<?php
function addFunction ( $number1, $number2, $number3 ) {
$sum = $number1 + $number2 + $number3;
echo "Sum of the three numbers is : $sum" ;
}
addFunction( 10, 20, 40);
?>
function addFunction ( $number1, $number2, $number3 ) {
$sum = $number1 + $number2 + $number3;
echo "Sum of the three numbers is : $sum" ;
}
addFunction( 10, 20, 40);
?>
The PHP cod above will display this result -
php function, exist, return, return array, get _exists, as argument
PHP Function, Creating PHP Function - how? - example - php tutorial
Online Editor
This tool makes it easy to create, adjust, and experiment with custom colors for the web.
HTML Templates

Magnews2 is a modern and creative free magazine and news website template that will help you kick off your online project in style.
CSS HTML Layout

Find here examples of creative and unique website layouts.
Free CSS HTML Menu

Find here examples of creative and unique website CSS HTML menu.