Monday, May 12, 2014
Monday, May 5, 2014
12.What is Function?
Function is a block of code that it will process and when we called it .
Function has the following advantages :
- Reduction of the same coding
- Easy Error
- Line of Code
- Time
Function is divided into two types :
- Pre-defined Function (Built-in Function)
- Manual Function (User define Function)
Pre-defined Function
- Abs ($ x)
abs ($ x) user Functin for providing absolute value to $ x.
- Round ($ x)
round ($ x) user Functin for only around $ x.
- Ceil ($ x)
ceil ($ x) user Functin for integer values greater than the value of $ x.
- Date (string format, int timestamp)
- d: day
- L: full day
- M: month
- F: full month
- Y: full year
- y: year
- Time ()
Function used to display the date.
example
Function has the following advantages :
- Reduction of the same coding
- Easy Error
- Line of Code
- Time
Function is divided into two types :
- Pre-defined Function (Built-in Function)
- Manual Function (User define Function)
Pre-defined Function
- Abs ($ x)
abs ($ x) user Functin for providing absolute value to $ x.
- Round ($ x)
round ($ x) user Functin for only around $ x.
- Ceil ($ x)
ceil ($ x) user Functin for integer values greater than the value of $ x.
- Date (string format, int timestamp)
- d: day
- L: full day
- M: month
- F: full month
- Y: full year
- y: year
- Time ()
Function used to display the date.
example
echo date("l, F dS , Y",strtotime("2010/12/23"))";echo date("l , F d , Y H : i : s", time());ResultThursday, December 23rd , 2010Saturday , March 12 , 2011 14 : 30 : 45Manual Function
1. No Parameter Function
Syntax
Syntax
function functionName(){ statements;}Note:
- Naming Function is we have to put it is the process of our Function.
- Function names begin with letters or _ but we can not start with numbers.
How to call funtionfunctionName();example<?php function printWelcome() { echo "Welcome to www.itkonkhmer.com"; } echo "Hello all visitor"; printWelcome();?>2. Parameter Function
Syntaxfunction functionName($par1,$par2,...){ statements;}How to call functionfunctionName(($par1,$par2,...);examplefunction UserWelcome($name,$id){ echo "Hello " . $name; echo "ID : " . $id ;}UserWelcome("Visiter","027RT");ResultHello VisitorID : 027RT3. Returning Function
Syntaxfunction functionName($par1,$par2,...){ statements; return value;}4. Pass by value, pass by reference parameter
- Pass by value: Argument is such that it does not provide value to the Parameter value attached to it.
- Pass by value: Argument is such that it needs to provide value to the Parameter assigned to it by using signs.
Results After calling function PassByValue a=10After calling function PassByReference b=21
Subscribe to:
Posts (Atom)





