X
HOME HTML CSS JAVASCRIPT SQL PHP JQUERY ANGULAR XML ASP.NET MORE...
REFERENCES | EXAMPLES | FORUM | ABOUT

PHP 5 Constants


Constants are like variables except that once they are defined they cannot be changed or undefined.


PHP Constants

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.


Set a PHP Constant

To set a constant, use the define() function - it takes three parameters: The first parameter defines the name of the constant, the second parameter defines the value of the constant, and the optional third parameter specifies whether the constant name should be case-insensitive. Default is false.

The example below creates a case-sensitive constant, with the value of "Welcome to W3Schools.com!":

Example

<?php
define("GREETING", "Welcome to W3Schools.com!");
echo GREETING;
?>

Run example »

The example below creates a case-insensitive constant, with the value of "Welcome to W3Schools.com!":

Example

<?php
define("GREETING", "Welcome to W3Schools.com!", true);
echo greeting;
?>

Run example »



Your suggestion:

Close [X]

Thank You For Helping Us!

Your message has been sent to W3Schools.

Close [X]
Search w3schools.com:

WEB HOSTING

UK Reseller Hosting

WEB BUILDING

Download XML Editor FREE Website BUILDER Free HTML5 Templates FREE Website Templates Free HTML Templates

SHARE THIS PAGE

facebook