answersLogoWhite

0

You can define a constant using the define() directive.

you can use this a number of ways;

to define a variable to a constant do:

$string = "hello";

define("string",$string);

to define a string to a constant use:

define("hello","there");

to define a integer or other numerical value use:

define("number",1.0);

Summery:

to define a string use quotes as you would do a string.

Unlike variables in PHP a constant cannot be changed or undefined once it is defined. Constant remains automatically globally throughout the script. It means that it can be accessed from inside a function. e.g.

define("Program" , "This is my first line of code!");

function simTest() {

echo Program;

}

simTest();

?>

User Avatar

Wiki User

9y ago

Still curious? Ask our experts.

Chat with our AI personalities

ViviVivi
Your ride-or-die bestie who's seen you through every high and low.
Chat with Vivi
MaxineMaxine
I respect you enough to keep it real.
Chat with Maxine
TaigaTaiga
Every great hero faces trials, and you—yes, YOU—are no exception!
Chat with Taiga

Add your answer:

Earn +20 pts
Q: How do you define a constant in PHP?
Write your answer...
Submit
Still have questions?
magnify glass
imp