Home > DeveloperSection > Articles > PHP Constant and PHP Variables

PHP Constant and PHP Variables

PHP PHP  Variable 
1 Comment(s)
 530  View(s)
Rate this:

PHP Constant and PHP Variables  

PHP Constant

·     A constant is an identifier or a name.These constant value remains the same during the execution of script.

·     Constant are like variable except  once the value is assigned to the constant it remains the same throughout the script.

·        Constant are case sensitive.

·        Note:Unlike Variable constant are global across the entire script.

·        Unlike variable you do not need to define $ sign before the name of a constant.

·       A constant name starts with underscore or letter,followed by number letter or underscore.when you have defined the constant ,it can never be changed.

Following is an example:

To create a php constant use define() function:

Syntax: define(name,value,case-sensitive);

 name:name of the constant.

 Value:value of the contant.

 Case-sensitive:specifies whether it shoud be case-sensitive or not.By default it is false.


define("text", "Hello World!!",true);

echo text;




Hello World!!


Constant are Global:


Contant are global and can be used anywhere in the script.


define("text", "Hello World!!",true);

function myPhp() {

    echo text;






Hello World!!

PHP Variables

What are Variables?

Variable means to store a value, such as text string “Hello Everyone!” or the integer value 4.A variable can then be reused throughout your code,instead of using the actual value over and over again.Here are the most important things to know about about variables in php:

  • A variable starts with the $ sign, followed by the name of variable.
  • PHP variables should be alpha-numeric and underscores.(a-z,A-z,0-9,or _).
  • Variable are case sensitive.($text and $Text both are two different thing).
  • Variables with more than one word must be separated by underscore.($my_text).





echo(“$text World!”);



Result: Hello World!

wonderful article

By Sunil Singh on   4 months ago
This is a wonderful article. It gives all the details in short and sweet.

Don't want to miss updates? Please click the below button!

Follow MindStick