programming languages tutorials

programming languages tutorials


function in php

Posted: 01 Jan 2013 07:54 AM PST

PHP Functions
The real power of PHP comes from its functions.
In PHP - there are more than 700 built-in functions available.

PHP Functions:
In this tutorial we will show you how to create your own functions.
For a reference and examples of the built-in functions.
Creating PHP functions:
• All functions start with the word "function()"
• Name the function - It should be possible to understand what the function does by its
name. The name can start with a letter or underscore (not a number)
• Add a "{" - The function code starts after the opening curly brace
• Insert the function code
• Add a "}" - The function is finished by a closing curly brace

Use a PHP Function
Now we will use the function in a PHP script:

<html>
<body>
<?php
function writeMyName()
{
echo "Kai Jim Refsnes";
}
echo "Hello world!";
echo "My name is ";
writeMyName();
echo ".That's right, ";
writeMyName();
echo " is my name.";
?>
</body>
</html>


The output of the code above will be:


Hello world!
My name is Kai Jim Refsnes.
That's right, Kai Jim Refsnes is my name.


Post a Comment