Php – Constant – POFTUT

Php – Constant


[rps-include post=6522]

We have mainly worked with variables up to now. In most situations we need to use variables. But there are some exceptions where we need more reliable and constant values those will not changed during the execution of the applications. Php provides the constant type. Constants are designed to not changed during the application’s execution.

Define Constant

We will define constants with define function. We will provide the name of the constant and the value the constant will refer. In this example we will define Pi number as constant because it can not be changed because of its mathematical meaning and position.

define("PI",3.14);

echo "Pi number is ".PI;

As a general habit constants  generally defined with the uppercase letters. We can not only define numeric constants also string constants like below.

define("SITE","www.poftut.com");

[rps-include post=6522]

LEARN MORE  C Constants and Define Preprocessor

Leave a Comment