PHP

 Home  Computers & Internet  Web Programming PHP
What is PHP?
Echo
Comments
Variables
Constants
Data Types
number_format()
Character Strings
Mathematical Operators
Comparison Operators
Logical Operators
Joining Strings
explode()
implode()
strtolower()
strtoupper()
strlen()
ucfirst()
ucwords()
strrev()
str_replace()
str_repeat()
trim()
strip_tags()
addslashes()
stripslashes()
strpos()
strrpos()
nl2br()
isset()
unset()
empty()
POST
GET
If Statements
If Else Statements
Elseif Statements
Switch Statements
For Loops
While Loops
Do While Loops
Foreach Loops
File Create
File Open
File Read
File Write
File Delete
fgets()
file_get_contents()
Date & Time
$_SERVER
Sessions
Cookies
Arrays

HOW TO USE CONSTANTS IN PHP

Constants are similar to variables in that they are containers that hold value. However, a constant’s value once set, cannot be changed in a script. Constants also do not have a $ in front like variables do. It is good programming practice to name constants in capitals, although PHP will also accept lowercase.

Use constants for a value that you know is set and won’t change in the script.

To declare a constant:

define("nameofconstant", "valueofconstant");

Example:

<?

define("TAX","0.10");

?>

This will declare a constant called TAX with a set value of 0.10.

Anywhere in your script, you an simply use the word TAX and PHP will know the value will be 0.10.

Example:

<?

$taxable=5000 * TAX;  // equivalent to 5000 * 0.10

echo $taxable; // outputs 500

?>

Home | Privacy Policy | Terms Of Use | Contact Us