Functions are shortcuts for commonly used chunks of code. They make programming much easier because you don’t have to re-use long code snippets.A function is a particular piece of code, which does some processing, and can be accessed from anywhere within the program.
There are already more than 1000 of built-in library functions created for a different area, but we can create our own functions .
While creating a function its name should start with keyword function and all the PHP code should be put inside { and } characters.
function functionName(parameters)
{
// code to be executed;
}
Build-in Functions:
PHP Array functions :
PHP Calender Functions :
PHP Date & Time Functions:
PHP User-defined functions :
PHP allows us to create our own customised functions called the user-defined functions.User defined functions in PHP enable coders to create custom block of codes for specific events. Function declaration starts with the word function.Function name should start with a letter or underscore and it can never be a number. While declaring function, the best practice is to give a name which suggests the purpose of the function.
Example :
Output : 9