How to Define a Constant in PHP? Is $ symbol necessary?
Answers were Sorted based on User's Feedback
Answer / saurabh rastogi
define("CONSTANT", "Hello world.");
echo CONSTANT; // Outputs Hello world
| Is This Answer Correct ? | 46 Yes | 3 No |
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 |
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 |
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 |
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 |
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 |
Tell me how can we determine whether a php variable is an instantiated object of a certain class?
Maine 12th ke bad 2 years ka web designing ka course kiya hai. Php me achcha hu. Ek fresher ko is field me kitna mil sakta hai ?
what are interfaces and Abstart classes
How to connect to a url in php?
Explain soundex() and metaphone().
How to create reusable code in php?
How to open a file in php?
What is delimiter php?
What is a definer in mysql?
How does the identity operator ===compare two values in PHP?
How can we submit from without a submit button?
What is the maximum size of a file that can be uploaded using PHP and how can we change this?