0% found this document useful (0 votes)
29 views

PHP Tizag Tutorial-36

The document provides instructions on how to add a PHP function to a simple PHP script and call the function twice. It shows the original PHP script, the PHP script with a sample "myCompanyMotto" function added, and the resulting display output. It emphasizes that functions allow code reuse and there are many opportunities for errors, so when creating functions always use the function keyword, ensure the code is between braces, spell the name correctly when calling, and don't give up if errors occur.

Uploaded by

Anil Kumar
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
29 views

PHP Tizag Tutorial-36

The document provides instructions on how to add a PHP function to a simple PHP script and call the function twice. It shows the original PHP script, the PHP script with a sample "myCompanyMotto" function added, and the resulting display output. It emphasizes that functions allow code reuse and there are many opportunities for errors, so when creating functions always use the function keyword, ensure the code is between braces, spell the name correctly when calling, and don't give up if errors occur.

Uploaded by

Anil Kumar
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

Using Your PHP Function

Now that you have completed coding your PHP function, it's time to put it through a test run. Below is a
simple PHP script. Let's do two things: add the function code to it and use the function twice.

PHP Code:
<?php
echo "Welcome to Tizag.com <br />";
echo "Well, thanks for stopping by! <br />";
echo "and remember... <br />";
?>

PHP Code with Function:


<?php
function myCompanyMotto(){
echo "We deliver quantity, not quality!<br />";
}
echo "Welcome to Tizag.com <br />";
myCompanyMotto();
echo "Well, thanks for stopping by! <br />";
echo "and remember... <br />";
myCompanyMotto();
?>

Display:
Welcome to Tizag.com
We deliver quantity, not quality!
Well, thanks for stopping by!
and remember...
We deliver quantity, not quality!

Although this was a simple example, it's important to understand that there is a lot going on and there are
a lot of areas to make errors. When you are creating a function, follow these simple guidelines:

• Always start your function with the keyword function


• Remember that your function's code must be between the "{" and the "}"
• When you are using your function, be sure you spell the function name correctly
• Don't give up!

You might also like