A function is a separate block of code that is created to be used repeatedly in a program by the script as required.
Besides all the hundreds of built-in functions (of predefined) integrated within the PHP, they also allow users to create their own functions. These codes under a function label will not be executed unless it is called (evoked) by the main program scope.
Syntax for a user-defined function
<?php
function myFunction()
{
//...code here
}
// call
myFunction();
?>
Arguments of a function
Arguments of a function may be passed through the function calling; if a value needs to be manipulated, altered or to be used in a function, it can be transferred through arguments of the function.
Example of PHP function arguments
Return values of a function
A value of a function may also be returned from a function by including a return statement in the code. The function will then return to the point from where it was called at, with the value passed as a result of the function code execution.
Example of PHP function return values
Comments
No comments have been made yet.
Please login to leave a comment. Login now