PHP Functions



PHP Tutorial > PHP Commands > Functions

Similar to other programming languages, PHP provides a way for programmers to define functions, which can then be called elsewhere in the program. The syntax for a function is:

function "function_name" (arg1, arg2...)
{
  [code to execute]
  return [final_result];
}

where [final_result] is typically the variable holding the final value to be returned from the function.

Let's take a look at an example:

function double_this_number($input_number)
{
  return $input_number*2;
}

Elsewhere in the PHP code, we have

$x = 10;
$y = double_this_number($x);
print $y;

The output will be

20

Next: PHP Array




Copyright © 2013   1keydata.com  All Rights Reserved.  Privacy Policy


PHP Variables
PHP Operators
PHP IF ELSE
PHP ELSEIF
PHP Switch
PHP While Loop
PHP FOR Loop
PHP DO WHILE Loop
PHP FOREACH Loop
PHP INCLUDE
PHP Functions
PHP ARRAY
PHP FORMS
PHP Cookies
PHP Redirect
PHP MySQL

PHP Syntax

PHP Sitemap

PHP Resources