Create a User Defined Function in PHP

User Defined Function in PHP

User Defined Function in PHP

A user defined function declaration starts with the word “function”:

Syntax

Note: A function name can start with a letter or underscore (not a number).

Tip: Give the function a name that reflects what the function does!

Function names are NOT case-sensitive.

In the example below, we create a function named “writeMsg()”. The opening curly brace ( { ) indicates the beginning of the function code and the closing curly brace ( } ) indicates the end of the function. The function outputs “Hello world!”. To call the function, just write its name:

Example

You may also like

Leave a Reply

Your email address will not be published. Required fields are marked *