Constant in PHP

Posted on Updated on

Constant in PHP

Constant opposite of the variable like variable can change during the execution of the program. But constant remain the same at the execution time. Constant are use when we need only value which we don’t want to change like vat tax which is remain same for all. Constant start with letter not with the dollar ( $ ) sign as we declare the variable.

We use the define method with three parameter which are :

Name : – Which is use for name of the constant .

Value :- Which is use for give the value to the constant .

Case-insensitive : – It is by default false we can set the true which is use for when we call the name we can use both case of the letter.

Syntax for the constant :

Define ( name , value , case-sensitive , case-insensitive ) ;

For example :

< !DOCTYPE html >

< html >

< head >

< title > constant < / title >

< / head >

< body >

< ? php

Define ( “ GREEN “ , “ hello dear how are you this is my constant “ ) ;

Echo GREEN ;

? >

< / body >

< / html >

Output :

Hello dear how are you this is my constant.

Case-insensitive :

In case insensitive we can call it with small or capital letter no matter the name should be same. We have to just true the value third parameter in the define function.

Syntax :

Define ( name , value , true ) ;

For example :

< !DOCTYPE html >

< html >

< head >

< title > Case-Insensitive Constant < / title >

< / head >

< body >

< ? php

Define ( “ GREEN “ , “ hello dear how are you this is my case-insensitive constant “ , true ) ;

Echo green ;

? >

< / body >

< / html >

Output :

hello dear how are you this is my case-insensitive constant.

Global Constant : –

Constant are the global we can use them in the entire program . we just define once and we can call them at any where in the php coding.

Let see one example of the global constant :

< !DOCTYPE html >

< html >

< head >

< title > Global Constant < / title >

< / head >

< body >

< ? php

Define ( “ GREEN “ , “ hello dear how are you this is my Global constant “ , true ) ;

Function my _ test _ global _ constant ( )

{

Echo green ;

}

My _ test _ global _ constant ( ) ;

? >

< / body >

< / html >

Output :

hello dear how are you this is my Global constant

For more details and queries please feel free to email, visit or call us. Wishing you the very best for all your future endeavors.

Helpline: 9814666333, 8699444666

Email:info@technocampus.co.in

**************************************************************************************************************

Please fill the FORM and we shall contact you soon.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s