Thursday, April 4, 2013

PHP Functions => Syntax


What is Functions?

It is group of statement, that perform specific task. for example, we have an array want to sort the array in ascending order.
"Sort" is function in php that can do this. "sort" function is made by php.

The function which user defined according to their need is called user-defined functions. For defining any function their is set of rules which you have to follow.

Following are the Rules for defining function.

  • function name must start with alphabets (a-z)
  • function name can have alphabets(a-z), number(0-9) and underscore (_)
  • Before the function name, you have to write "function" that declare that you are defining the function
  • Function can have one or more arguments
  • Function start / end with cury braces ({})
  • function argument are enclosed within bracket i.e (,)
  • If when their is more than one argument, use comma (,) to separate them
  • Function are case -sensitive
Following are the example of a function that convert a string to upper-case and remove the extra spaces from left and right side.

function change($string){
  return strtoupper(trim($string));  
}
echo change('arun ');
Here $string is parameter passed in function.

No comments:

Post a Comment