Friday, March 6, 2009

PHP Tutorial - Constants in PHP

  Kaushal Patel       Friday, March 6, 2009

A constant contains data just like variables, but once you have assigned a value to Constants, you can't change it. It means Constants have a single value throughout the program. Thus it is different from PHP Variables. Defining Constants is different then defining Variable in PHP. Constants do not have a $ before their names. By convention, usually constants are uppercase names. See the example...

define("BIRTHDATE", "1/1/1983");

Whenever you wish to reference it within the body of code, you can do so simply by using its name.

echo(BIRTHDATE);

Constants can contain only scalar values (numbers and string). You can access the Constants everywhere in the program as it has global scope. You can use it even in the functions after the have been declared.


logoblog

Thanks for reading PHP Tutorial - Constants in PHP

Previous
« Prev Post

No comments:

Post a Comment