Cazpa.com PHP Developer & Website Designer

2May/107

PHP Tutorials: Sending email (Part 2)

Using the mail function, I show you how to create a very basic script. With a little tweaking of our php.ini file, we can send an email from php very easily!

26Apr/1018

PHP Tutorials: Sending email (Part 1)

Using the mail function, I show you how to create a very basic script. With a little tweaking of our php.ini file, we can send an email from php very easily!

31Mar/1020

PHP Basics: Echo Function

The echo function lets you output to a page. An almost vital function that you need to know!

5Mar/1011

PHP Basics: Advanced function

Not the trickiest example function, however this will teach you how to output a value created from within the function.

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!

   
Powered by WordPress Lab