Friday, June 21, 2013

php functions

php functions
what is a function in php?
A function in php is a set of codes that we want to execute it.:
function name of function(parameter)
{
what we want to do
}
The parameter is like a variable, you will understand when we do the example.
But what is the importance of a function? To know that lets do an example.
We want to create a function to calculate the sum of two numbers (just an example) the code is:

<?php
function snumbers($n1,$n2)
{
echo "$n1"+"$n2"; 
}
snumbers("5","10"); we just type the name of function and the value of parameters
?>

We will see 15 on the screen, so the importance of php functions is if we need to execute the code many times we don't need to rewrite the code, we just write it one time in a function and when we need it we just call the function name and the code will be executed.
This was the php functions lesson I hope you enjoy it.

And remembre that the real power of php language comes from it's functions

see you next time.

Share This!



No comments :

Post a Comment