Constants: Difference between revisions
Mr. MacKenty (talk | contribs) No edit summary |
Mr. MacKenty (talk | contribs) |
||
Line 17: | Line 17: | ||
# for the remainder of the running of this program, the value of SCHOOL_YEAR will be 2016 - 2017 | # for the remainder of the running of this program, the value of SCHOOL_YEAR will be 2016 - 2017 | ||
# If we wanted to CALL (use) a constant, we might use the following syntax: note the lack of a $ symbol\\ | |||
echo "The school year is " . SCHOOL_YEAR; | |||
?> | ?> |
Revision as of 05:09, 27 September 2016
In computer programming, a constant is an identifier with an associated value which cannot be altered by the program during normal execution – the value of the constant is, well, constant[2].
A constant is an identifier (name) for a simple value. As the name suggests, that value cannot change during the execution of the script. A constant is case-sensitive by default. By convention, constant identifiers are always uppercase.[3].
Example[edit]
Below is an example of declaring a constant in PHP:
<?php
# this file is used to demonstrate constants in PHP
define("SCHOOL_YEAR", "2016 - 2017");
# for the remainder of the running of this program, the value of SCHOOL_YEAR will be 2016 - 2017
# If we wanted to CALL (use) a constant, we might use the following syntax: note the lack of a $ symbol\\
echo "The school year is " . SCHOOL_YEAR;
?>
Standards[edit]
- Define the terms: variable, constant, operator, object.