PHP Function
PHP Tutorial » PHP Function
What are PHP functions?
A function is a piece of code that receives one or more parameter then process and returns a value.
PHP has a huge collection of internal functions that can call directly into your PHP code to perform a specific task as: gettype (), print_r (), var_dump, fopen(), fread() etc.
- A function will not execute automatically when a page loads on browser.
- A function will be executed when is called.
Syntax:
function functionName()
{
code to be executed;
}
?>
Create PHP Function
Let's create a PHP function that will write a simply message to your browser when you call it.
<?php
/* Defining a PHP Function */
function write_Message() {
echo "Welcome to agernic.com.
Today we will have a new lesson:
how to create a function in PHP";
}
/* Calling a PHP Function */
write_Message();
?>
Output: Welcome to agernic.com. Today we will have a new lesson: how to create a function in PHP
Related subjects:
PHP syntax
What is an array
PHP variabl
Array to comma separated
Tags: php function: function use, return, return type, parameters. optional parameter, exists, use external variable, default parameter value, return array, function list
What are PHP functions?
What is PHP function with examples?
What is PHP function name?
Are there functions in PHP?
PHP Functions with Parameters
When you define a function you can specify parameters to accept input values
The parameters work as variables inside function
<?php
function sumFunction($num_1, $num_2) {
$my_sum = $num_1 + $num_2;
echo "Sum of this two numbers is : $my_sum";
}
sumFunction(34, 21);
?>
Output: Sum of this two numbers is : 55
To see the result of the PHP code above please click Execute
PHP Function Arguments
An argument is like a variable
You can add as many arguments you need, pnly separate them with a comma.
<?php function surName($famname) {
echo "$famname Jones.<br>";
} surName("Janet");
surName("Gregor");
surName("Stanly");
surName("Jim");
surName("Korg");
?>
php function: function use, return, return type, parameters. optional parameter, exists, use external variable, default parameter value, return array, function list
What are PHP functions?
What is PHP function with examples?
What is PHP function name?
Are there functions in PHP?
PHP Function, Creating PHP Function - how? - example - php tutorial
This tool makes it easy to create, adjust, and experiment with custom colors for the web.

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

Find here examples of creative and unique website layouts.

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