Defining and calling functions php
In PHP web development script, you can easily declare and call user defined functions in any webpage website when needed. To easily define and call a function in PHP web development script, you need to follow some basic steps.

Defining Basic Functions in PHP.
To define and declare a user defined function in PHP web development script, you can use the function keyword in PHP, after which you use the name of the custom PHP function, brackets (), and curly braces {}. Here inside this declare function, you write the script source code that you want to execute in the existing PHP script.
Basic Function Declaration Example in PHP.
<?php
function message() {
echo “Hi, vanhelpsu!”;
}
?>
Calling a function in PHP script.
To call a function in PHP web development script, you just need to use the name of that user defined function, and after this you use brackets () to call the function.
Function call example in PHP script.
<?php
message(); // This will call the message function and print “Hi, vanhelpsu!”
?>
Functions with parameters in PHP web development script.
In PHP web development script you can also declare and define functions that accept arguments or parameters from the user. These are the values in the PHP script that are passed along with the actual formal arguments when the function is called.
Functions with parameters in PHP example.
<?php
function welcome($company) {
echo “Hi, $company!”;
}
?>
<?php
welcome(“Vanhelpsu”); // result is – hi, vcanhelpsu!
?>
Functions with return values in PHP web development scripts.
In PHP web development scripts you can return the desired value from the function using the return keyword.
Functions with return values PHP Example.
<?php
function total($p, $q) {
return $p + $q;
}
?>
<?php
$output = total(1, 2);
echo $output; // the result is – 3
?>
Defining functions in PHP web development scripts.
<?php
// Define a simple function that adds two p and q numbers
function suminteger($p, $q) {
return $p + $q;
}
?>
Calling functions in PHP web development scripts.
<?php
// it Call the above function and pass argument values
$outout = suminteger(3, 9);
// the result is
echo “The sum integer is – ” . $output;
?>
Explanation in PHP web development script.
Defining a function in a PHP script.
Here is the function suminteger($p, $q) – It defines a function called suminteger that accepts two parameters, $p and $q arguments, from the user.
Where return function type has $p + $q;: The function adds the values of $p and $q, and returns the result.
Calling a function in a PHP script.
suminteger(3, 9); – It calls the suminteger function, passing 3 and 9 as arguments. And the function returns the output value 12.
echo “The sum integer is – ” . $output; – This function prints the result of calling the suminteger in the current script.
Explanation in PHP web development script.
- Defining a function in PHP – Here the function is declared with functionName() { // code }.
- Calling a function in PHP – In PHP web development scripts, the function is called with functionName();.
- Function with parameters in PHP – Here the function parameter argument is declared with functionName($func1, $func2) in PHP web development scripts.
- Function with return value in PHP – In PHP web development scripts, the function return nature has to be defined to return the desired function value.