DJ Mike's Tutorials: PHP


< ^ >

Built in Functions

There are two categories of functions; those built in to PHP and those you define yourself. There are hundreds of functions built into PHP. A function takes some kind of input, called an argument and usually returns some kind of output. A function may accept more than one argument. If it does they are separated by commas.

function_1( $argument_1, $argument_2, $argument_3 );

An example of a function that accepts a single argument is the square root function

<?
$x 
25;
$ysqrt($x);
echo 
"$y"# returns 5 
?>


An example of a function that accepts a two arguments is the pow() function:

<?
$x 
2;
$y 3
$z pow($x$y);
echo 
$z# outputs 8 (2 to the 3rd power)
?>

Any kind of variable may be an argument including numbers, strings, arrays and objects. The results of one function may be the argument of another:

function_2(function_1($var));

The code below will first find the square root of 25 then raise the result to the 3rd power:

<?
$x 
25;
$x powsqrt($x), );
echo 
$x# outputs 125
?>

More Functions

There are many more functions, more than the scope of this tutorial but I made some short lists of functions with examples. For a complete list, see the PHP Manual.

String Functions
Math Functions
Array Functions
File Functions
PHP: Function Reference - Manual

< ^ >



Created by DJ Mike from Santa Barbara

DJ Mike


Dance Away Santa Barbara's Home Page
<a href="http://www.statcounter.com/" target="_blank"> <img src="http://c5.statcounter.com/counter.php?sc_project=1321035&java=0&security=da2193dc" alt="counter free hit invisible" border="0" /></a>