Welcome to PHPMule.com
A blog site which I am posting to during my learning of the popular programming language PHP. Feel free to leave comments!
-
PHP - Constants
A constant in PHP stores a value like a variable but if a Constant is given a value it can’t be changed in the script.
To declare a constant you have to set it out in the following way. Let’s say we wanted to give a chocolate cake a fixed price:
define(’CHOCOLATECAKE’, 1.50);
or even a swiss roll! ummm
define(’SWISSROLL’, 1.25);
If you wanted to use a constant all you have to do is use the name of the Constant such as:
echo CHOCOLATECAKE;
or even:
echo SWISSROLL;
Using these Constants will obviously output the price to the browser. You can use these constants to work out the total cost of both by using Variables and Constants together:
$totalcost = CHOCOLATECAKE + SWISSROLL;
The $totalcost now has a value of 2.75 and subsequently this variable is now of the ‘float’ data type as it’s a decimal number. You can see why PHP is a very good language to build customer order forms etc. You now have a variable that has a value and we can now output this to the browser:
echo “Total cost of your order: £” . $totalcost . “. Thanks for visiting!”;
As you can see you can effectively use constants and variables together!
(Post created on Monday, April 6th 09 at 14:15)
1 Trackbacks / Pingbacks
-
Buy:Ventolin.Amoxicillin.Seroquel.Prozac.Buspar.Benicar.Lipothin.Female Pink Viagra.Zetia.Zocor.Acomplia.Wellbutrin SR.Lasix.Female Cialis.Advair.Aricept.Cozaar.Lipitor.Nymphomax.SleepWell….
Leave a reply
-
-
Archives
Recent Articles
- PHP - Rounding Off Numbers
- PHP - Single vs Double Quotation Marks
- PHP - Loading Files Into Your PHP Script By Using require() and include()
- PHP - Replacing Strings With Other Strings
- PHP - Finding Strings Within Strings
- PHP - Using strlen() To Test String Length
- PHP - Using The explode() Function
- PHP - Changing The String Case
- PHP - The nl2br() Function
- PHP - Trimming Strings
Links
Categories
- PHP (22)
- Uncategorized (1)



JAMES September 7th, 2010 at 14:21