Translate

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

echo date("l, F dS , Y",strtotime("2010/12/23"))";
echo date("l , F d , Y H : i : s", time());
Result
Thursday, December 23rd , 2010
Saturday , March 12 , 2011 14 : 30 : 45

Manual Function

1. No Parameter Function
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 funtion
functionName();
example
<?php
 function printWelcome()
 {
   echo "Welcome to www.itkonkhmer.com";
 }
 echo "Hello all visitor";
  printWelcome();
?>
2. Parameter Function
Syntax
function functionName($par1,$par2,...)
{
   statements;
}
How to call function
functionName(($par1,$par2,...);
example
function UserWelcome($name,$id)
{
    echo "Hello " . $name;
    echo "ID : " . $id ;
}
UserWelcome("Visiter","027RT");
Result
Hello Visitor
ID : 027RT
3. Returning Function
Syntax
function 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=10
After calling function PassByReference b=21




0 comments:

Post a Comment