define() - Defining Constants

Q

How do you define a constant in PHP?

✍: FYIcenter

A

You can define a constant by using the define() function. Once a constant is defined, it can never be changed or undefined. For example:

<?php
define("CONSTANT", "Hello world.");
echo CONSTANT; // outputs "Hello world."
echo Constant; // outputs "Constant" and issues a
notice.
?>

Only scalar data (boolean, integer, float and string) can be contained in constants.

2007-02-27, 5683👍, 0💬