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

Answer Posted / 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



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Where to put php files in apache server?

509


Is php front end or back end?

513


Tell me what is htaccess?

493


What is a php array?

498


How be the result set of mysql handled in php?

591






What are the functions used in php?

510


How to declare an array in php?

545


When do you use define() and when do you use const. What are the main differences between those two?

580


Is php better than python?

557


How many functions are there in php?

522


Is php procedural or oop?

565


Which methods should be used for sending an email using the variables $to, $subject, and $body?

569


What is rest api in php?

518


Where php basically used?

569


What is a php namespace?

521