MY mENU


Monday 10 September 2012

PHP Functions

function is something that performs a specific task. People write functions if they plan on doing the same task over and over again. This allows you to only write the code once and save a lot of time and space.
Although in the next few pages we will lean how to write our own functions, PHP has several functions that already exist for us to use. Although they all have different uses, all functions are phrased as: name(argument). The name being the name of the function, and the argument being the value(s) it is using.
Here are some examples of functions already in PHP:
 "; 
 print "The square root of 16 is " . $b . "
"; 
 print "12.3 rounded is " . $c . " and 12.5 rounded is " . round(12.5); 
 ?> 
This gives an example of three functions; absolute value, square root, and rounding. As you can see you can use the function right in the print statement or you can assign it to a variable. A list of functions can be found here.

No comments:

Post a Comment