| Course Others | You are Offering Professional Course | Locality Ganapathi |
What is PHP?
PHP started off being a small open source project that developed as more developers realized how powerful it was. RasmusLerdorf revealed the 1st version of PHP back in 1994.
PHP functions are similar to other programming languages. A function is a piece of code which takes one more input in the form of parameter and does some processing and returns a value.
You already have seen many functions like fopen() and fread() etc. They are built-in functions but PHP gives you option to create your own functions as well.
There are two parts which should be clear to you
Creating a PHP Function
Calling a PHP Function
In fact you hardly need to create your own PHP function because there are already more than 1000 of built-in library functions created for different area and you just need to call them according to your requirement.
Creating PHP Function
Its very easy to create your own PHP function. Suppose you want to create a PHP function which will simply write a simple message on your browser when you will call it. Following example creates a function called writeMessage() and then calls it just after creating it.
PHP Functions with Parameters
PHP gives you option to pass your parameters inside a function. You can pass as many as parameters your like. These parameters work like variables inside your function. Following example takes two integer parameters and add them together and then print them.
Passing Arguments by Reference
It is possible to pass arguments to functions by reference. This means that a reference to the variable is manipulated by the function rather than a copy of the variable's value.
Any changes made to an argument in these cases will change the value of the original variable. You can pass an argument by reference by adding an ampersand to the variable name in either the function call or the function definition.
PHP Functions returning value
A function can return a value using the return statement in conjunction with a value or object. return stops the execution of the function and sends the value back to the calling code.
You can return more than one value from a function using return array(1,2,3,4).
Setting Default Values for Function Parameters
You can set a parameter to have a default value if the function's caller doesn't pass it.
Dynamic Function Calls
It is possible to assign function names as strings to variables and then treat these variables exactly as you would the function name itself.
CONTACT FOR MORE INFORMATION: 9360029290,9442173717,9003206648,9943129290.
CONTACT EMAIL-ID : [email protected]
COIMBATORE: HEAD OFFICE
NO:96,HOPE COLLEGE BUS STOP,
OPP KRISHNA SWEETS,
PEELAMEDU,
AVINASHI ROAD,
COIMBATORE