PHP Function

PHP Function
Function are self contained block of statement which used to perform any specific task.

Types of Function

  1. system defined/library/inbuilt
  2. user defined

 

Advantages Of Function

=> A function is created once but used many times, often from more than one program.=> It reduces duplication within a program.=> Debugging and testing a program becomes easier when the program is subdivide.


 

How to define Function

A function will be executed by a call to the function.

Syntax

function function_name( )
	  {
		code to be executed;	
	  }	


There are 3 types of variables i.e used inside a function

  1. Local
  2. Global
  3. Static

Local Variable

=> Local variables are always initialize inside the function body.

=> Local variable cant work outside function body.

Global Variable

=> Global variables are always initialize outside the function body.

=> Global variable work inside the function body as well as outside function body.

=> To access Global variable we have to use global keyword.

Static Variable

=> When a function is completed, all of its variables are normally deleted.
=> However, sometimes you want a local variable to not be deleted then use static keyword.


 

Leave a comment