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.
<?phpAnother way of calling functions is using include()..
function MyFirstEchoFunction()
{
echo "Hi this is the function called! <br />";
echo "And this is text created by function!";
}MyFirstEchoFunction()
?>
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 :
<?phpIsn't this nice? The output of this file is :
include("test.php"); //This is the target php fileMyFirstEchoFunction() //We just called the function coded in test.php
?>
Hi this is the function called!
And this is text created by function!
1 comment:
Nice its simple and easy to undertand its ok.
Post a Comment