logo
g Text Version
Beauty & Self
Books & Music
Career
Computers
Education
Family
Food & Wine
Health & Fitness
Hobbies & Crafts
Home & Garden
Money
News & Politics
Relationships
Religion & Spirituality
Sports
Travel & Culture
TV & Movies

dailyclick
Bored? Games!
Nutrition
Postcards
Take a Quiz
Rate My Photo

new
Houseplants
Romance Movies
Creativity
Family Travel
Southwest USA
Irish Culture
Home Finance


dailyclick
All times in EST

Full Schedule
g
g PHP Site

BellaOnline's PHP Editor

g

The PHP Function and Function Call

Guest Author - Diane Cipollo

When you are studying PHP you will want to hand code every line in your program so that you can study how the code works. Somewhere along the way you will realize that there are certain tasks that your program needs to perform again and again. And therefore you find yourself writing the same lines of code again and again. For example there are several occasions when a visitor to your website would need to give you an email address. He may want to buy something, sign up for your newsletter or fill in a customer service form. Each time he enters his email address and submits the web form, you will want your program to check the accuracy of the email address. You could hand code this task at each location in your program that you need to check the email address. But that isn't very efficient. Well, PHP has an answer for this problem. It is called a function.

There are basically two types of PHP functions. The first type is the built-in function. These functions are already part of the PHP language and therefore you do not need to write them yourself. To use these built-in functions you just add a function call to your program. A function call is a piece of code that tells your program to "call in" the built-in function whenever you need it. The second type of function is the user defined function. These are the functions that you write yourself. Then, after you write the function, you can call it into your program any time by coding a function call. Let's take a look at the PHP code for a function call.

Basic PHP Code
function_name(argument, argument);

Example
print($message);


print();
function_name
This is the name given to the function and is how your program will identify the function. I have used the built-in print function as an example. The function_name for the print function is print and it is placed on the left side of the ( ).

print($message);
Parenthesis
The parenthesis are used to pass information to the function. If you do not need to pass any information then you will put nothing between the ( ).

$message
Argument
The argument is the information that you want to pass to the function. If you have more than one argument, separate them with a comma. Then place the argument(s) between the parenthesis. In our example, the argument (information) passed to the function is the $message variable which is placed between the parenthesis. The built-in print function will print whatever value you have given to the $message variable.

print($message);
;
The semicolon ends the function call

Note: A function usually passes information back to the program when the function is completed. For example the print function passes a Boolean back to the program.




This site needs an editor - click to learn more!

Add The+PHP+Function+and+Function+Call to Twitter Add The+PHP+Function+and+Function+Call to Facebook Add The+PHP+Function+and+Function+Call to MySpace Add The+PHP+Function+and+Function+Call to Del.icio.us Digg The+PHP+Function+and+Function+Call Add The+PHP+Function+and+Function+Call to Yahoo My Web Add The+PHP+Function+and+Function+Call to Google Bookmarks Add The+PHP+Function+and+Function+Call to Stumbleupon Add The+PHP+Function+and+Function+Call to Reddit




RSS | Editor's Picks Articles | Top Ten Articles | Previous Features | Site Map


For FREE email updates, subscribe to the PHP Newsletter


Past Issues


print
Printer Friendly
bookmark
Bookmark
tell friend
Tell a Friend
forum
Forum
email
Email Editor


Content copyright © 2014 by Diane Cipollo. All rights reserved.
This content was written by Diane Cipollo. If you wish to use this content in any manner, you need written permission. Contact BellaOnline Administration for details.

g


g features
Archives | Site Map

forum
Forum
email
Contact

Past Issues
memberscenter


vote
Poetry
Daily
Weekly
Monthly
Less than Monthly



BellaOnline on Facebook
g


| About BellaOnline | Privacy Policy | Advertising | Become an Editor |
Website copyright © 2014 Minerva WebWorks LLC. All rights reserved.


BellaOnline Editor