PHP Functions

In PHP, there are more than 700 built-in functions.
This chapter shows how to create your own functions. A function will be executed by a call to the function. You may call a function from anywhere within a page.
Syntax
1
2
3
4
   function functionName()
  {
    code to be executed;
    }
To add more functionality to a function, you can add parameters. A parameter is just like a variable.
Parameters are specified after the function name, inside the parentheses.
To let a function return a value, use the return statement (see the example below):
1
2
3
4
5
6
7
8
9
10
11
12
13
 
<html>
  <body>
    <?php
    function add($x,$y)
    {
    $total=$x+$y;
    return $total;
    }
        echo "6 + 9 = " . add(6,9);
    ?>
      </body>
  </html>

Output: 6 + 9 = 15

PHP For Loops
PHP Forms and User Input
PHP introduction
PHP Operators