Easy learning with example program codes

PHP Functions

A function is a piece of code that can be used repeatedly in a PHP program. A function is mainly of two types:

  • Built in Functions; which are already defined in PHP Library.
  • User Defined Functions; which are created and defined by users.


function functionName(parameters) 
    code to be executed;

Rules for using Functions:

  • Name of a function should not start with a number. It can start with a letter or underscore.
  • Name of a function are case-insensitive.
  • A function starts with an opening curly brace ( { ) and ends with a closing curly brace ( } ).
  • Arguments are the variables, inside the parentheses, after the function name which is used to pass informations to functions.
  • For multiple arguments, comma should be used for separation.
  • Default argument value can also be specified in a function. If no argument is specified, the function will take the default argument.
  • Functions can also be used to return value.


<!DOCTYPE html>
function writeMsg() {
	echo "My First Program using Function!";


My First Program using Function!
Posted in PHP   

Industrial Training

We offers Placement Oriented Training on Java, Spring, JSF, Hibernate, PHP, AngularJS, Angular 4, PLSQL, Oracle BI Publisher etc. We also provides Online training, please mail us at


We also provides the Development services for Website Development , Java Development, PHP Development, Android App Development etc. You can contact us on

Copyright © 2019 CodesJava Protection Status SiteMap Reference: Java Wiki