Php Functions

PHP functions are very useful, because once coded, it can be called from anywhere within the script or from outside. Note, code block must start with function word.

Example 1 : Shows how to call function within the php Script.

<?php

function MyFirstEchoFunction()

{

echo "Hi this is the function called! <br />";

echo "And this is text created by function!";

}

MyFirstEchoFunction()

?>

Another way of calling functions is using include()..
Php Include() lets you import any php or text file in your script.

Example 2 : Create a php file somthing like "test.php" and write this code:

test.php code :
<?php

function MyFirstEchoFunction()

{

echo "Hi this is the function called! <br />";

echo "And this is text created by function!";

}

MyFirstEchoFunction()

?>

Now create destination file, something like "call.php"

Call.php code :

<?php

include("test.php"); //This is the target php file

MyFirstEchoFunction() //We just called the function coded in test.php

?>

Isn't this nice? The output of this file is :
Hi this is the function called!
And this is text created by function!