Tuesday, 18 December 2012

Episode 11: Creating a function



You can create a function by putting the code into a function block. The general format is as follows:

function functionname()
{
block of statements;
return;
}

For example, you can create the function display_logo() that we discuss in the preceding section with the following statements:

function display_logo()
{
echo “<p><img src=’Images/logo.jpg’ width=’50’ height=’50’
hspace=’10’ align=’left’ /></p>”;
echo “<p style=’font-size: x-large’>My Fine Company</p>”;
echo “<p style=’font-style: italic’>quality products</p>”;
return;
}

You can then call the function anywhere you want to display the logo, as  follows:

display_logo();

The return statement at the end of the preceding function stops the function and returns control to the main script. A return statement isn’t needed at the end of the function, because the function stops at the end anyway and returns control to the calling script.



Written by “Shojib”.

No comments:

Post a Comment