Download - Php constants class 336

Transcript

PHP Constants

PHP ConstantsBy Daysi CastroLopezClass 336

Constants are variablesConstants are variables except that once they are defined they cant be changed or undefined.W3schools.com defines it as:A constant is an identifier (name) for a simple value. The value cannot be changed during the script.A valid constant name starts with a letter or underscore. (no $ sign before the constant name).Note:Unlike variables, constants are automatically global across the entire script.

Create a PHP constant You can create a constant by using the define () function.Use the define function to specify the name and value of a constant. (name, value, case-insensitive). Many programmers use capital letters to name constants so they stand out.Note: Since a constant can not be change you do not use a $ sign before its name when you declare it or (use it).

Parameters

name: Specifies the name of the constantvalue: Specifies the value of the constantcase-insensitive: Specifies whether the constant name should be case-insensitive. Default is false

How to declare constants

Examples: define(male, m) ; // a string constant

define(PI, 3.14159) ; // a double constant

PHP Constant ExamplesPHP source

Result

Welcome to W3Schools.com!

Sources

Harris, Ray and Murach, Joel Section 2: Master PHP Programming. Murachs PHP & MySQL. CA : Mike Murach and Associates, INC 2014.http://www.W3school.com/php/php_constants