Cazpa.com PHP Developer & Website Designer

6Dec/090

PHP Functions (Arguments & Values)

Creating a basic fuction

Functions are great for cutting down on code and making things easier to read when developing, you can create a function
for just about any process including conditional statements, loops or even calls to other functions.

This article will show you how to create simple functions for your applications and website's.

First things first we need to know how to define and invoke a function:

<?php
// Define your function
function displayEinsteinQuote()
{
	echo "Do not worry about your difficulties in Mathematics. I can assure you mine are still greater.";
}
?>
<?php
// Invoke your Albert Einstein Quote
displayEinsteinQuote()
?>

Once you invoke your function this will output:

Do not worry about your difficulties in Mathematics. I can assure you mine are still greater.

Now I know what you are thinking, why not just echo the quote to begin with? well the next example will show you how to use
a variable to create a more dynamic function

<?php
// Define your function with simple argument
function ConvertStoneToKilos($stone)
{
$diff = '6.35029318';
$total = ($stone*$diff);

	echo "$stone stone is the equivilant to $total kilograms";
}
?>
<?php
// Invoke the function
ConvertStoneToKilos(11);
?>

This will convert eleven stone into kilograms (69.85322498), of coarse changing the varaiable in the brackets will change the output!

About Daniel Smith

I am the boss around here, if you need anything then send me a message :))

Popular Content & Keywords

rails vs php performance,php define variable,warning: mail() [function mail]: smtp server response: 554 the message was rejected because it contains prohibited virus or spam content in,add update delete in php,php tutorial // user registration w/ sql,ruby on rails vs php,warning: mail() [function mail]: smtp server response: 554 the message was rejected because it contains prohibited virus or spam content,php define href with variables,twitter api php tutorial,facebook jsonwrapper,warning: mail() [function mail]: smtp server response: 554 the message was rejected because it contains prohibited virus or spam content in on line 15 error,adding records to a mysql database using php,web server administrator tutorials youtube,contactformprocess php,facebook jsonwrapper php
Comments (0) Trackbacks (0)

No comments yet.


Leave a comment

You must be logged in to post a comment.

No trackbacks yet.

Powered by WordPress Lab