Define keyword in Php
The define() function defines a constant.
Constants are much like variables, except for the following differences:
(i) Using define() INSIDE a class definition does not work..
(ii) A constant’s value cannot be changed after it is set.
(iii) Constants do not have a dollar sign ($) before them.
(iv) Constant values can only be strings and numbers.
Constants are much like variables, except for the following differences:
(i) Using define() INSIDE a class definition does not work..
(ii) A constant’s value cannot be changed after it is set.
(iii) Constants do not have a dollar sign ($) before them.
(iv) Constant values can only be strings and numbers.
Syntax:-
bool define ( string $name , mixed $value [, bool $case_insensitive = false ] )
Parameter
Description
$name
Required
$value
Required
$case_insensitive
Optional(false)
Note:-
(i) A valid constant name starts with a letter or underscore.
(ii) define keyword is used for global.
Example:-
<?php
define("IMAGE_WIDTH", 400px);
echo IMAGE_WIDTH; // outputs:- 400px
echo IMAGE_width; // outputs:- "IMAGE_width" and issues a notice
define("IMAGE_WIDTH", 400px, true);
echo IMAGE_WIDTH; // outputs 400px
echo IMAGE_width; // outputs 400px
?>