Friday, 6 February 2015

Function Parameter

As we see in precious example simple function example when we call that function its always do the same thing , what if we want to get dynamic values from functions? we use parameters with function,parameter also known as arguments.

Example:



<?php

// define custom function
function myfunction($myparameter) {
  
    echo $myparameter;

  
}
//call a function

myfunction("parameter1");

//each time its change value of function by pass argument
 
echo "<br/>";
myfunction("parameter2");
echo "<br/>";
myfunction("parameter3");
echo "<br/>";
myfunction("parameter4");
echo "<br/>";
myfunction("parameter5");
echo "<br/>";
//print output

parameter1
parameter2
parameter3
parameter4
parameter5
 ?>





This is also known as passing argument to function by value

Functions

As we know that php has its own built in function like other programming languages ,similarly in php we can build own functions, syntax for user defined function as below:



<?php
// define custom function function myfunction() {
   
       ...... // your code  }
//call a function
myfunction();
?>


Example:


<?php
/ define custom function
function myfunction() {
   
    echo"myfunction value";

   
}
//call a function

myfunction();

// print output myfunction value
?>