How to Define a Constant in PHP? Is $ symbol necessary?

Answers were Sorted based on User's Feedback



How to Define a Constant in PHP? Is $ symbol necessary? ..

Answer / saurabh rastogi

define("CONSTANT", "Hello world.");

echo CONSTANT; // Outputs Hello world

Is This Answer Correct ?    46 Yes 3 No

How to Define a Constant in PHP? Is $ symbol necessary? ..

Answer / abhishek baranwal

define("CONSTANT", "Hello world.");

echo CONSTANT; // Outputs Hello world


define("CONSTANT", "New Value");

echo CONSTANT; // Outputs Hello world

Means once you declair the define a constant value that
will become every time it will not take new value or it
will not redeclair.if you want change in value then declair
the variables for that purpose.

Is This Answer Correct ?    13 Yes 2 No

How to Define a Constant in PHP? Is $ symbol necessary? ..

Answer / dhir

Constant means a unchangeable value and in php we are
written in "".

"constant";

And don't need to $ sign.

Is This Answer Correct ?    16 Yes 7 No

How to Define a Constant in PHP? Is $ symbol necessary? ..

Answer / mahesh

A Dollar($) Symbol is not necessary for displaying a
constant6 variable,
ex:
define("PAGE_SIZE","100");
echo PAGE_SIZE;
or
<?=PAGE_SIZE?>

Is This Answer Correct ?    7 Yes 3 No

How to Define a Constant in PHP? Is $ symbol necessary? ..

Answer / nilsoft

define("CONSTANT", "Its constant");

echo CONSTANT; // Outputs Its Constant

There is no need to use $ sign for it.
$ sign is used for declare variables.

Is This Answer Correct ?    3 Yes 0 No

How to Define a Constant in PHP? Is $ symbol necessary? ..

Answer / vaneet badhan

define(my,60);

echo my;

output will be 60.

define(my,vaneet);

echo my;

output will be vaneet

Is This Answer Correct ?    7 Yes 12 No

Post New Answer

More PHP Interview Questions

Which function would you use to format date information in php?

0 Answers  


What is the difference between mysql_fetch_object and mysql_fetch_array?

10 Answers   Sarv,


What is a PHP accelerator?

0 Answers  


What are the php variables?

0 Answers  


What are sql functions?

0 Answers  






What types of loops exist in php?

0 Answers  


Explain what is the use of "echo" in php?

0 Answers  


Is array function in php?

0 Answers  


In How many ways can u represent Not equal?Give Syntax of all ways..

3 Answers  


What is the capacity of mysql database?

0 Answers  


Write syntax to open a file in php?

0 Answers  


What are php strings?

0 Answers  


Categories