PHP define() function
This is used to define a named constant. A Constant is a name for a value. Like if we want to give a name to a sentence 'What is in your mind'. We can assign a constant name to this sentence.Syntax
define("CONST_NAME", "Description");
Example
<?php
define("STATUS", "What is in your mind");
?>
Constant value cannot be changed during execution of the script.
Once a constant is initialized, it cannot be set to another value.
Constant name is accessed globally by default.
Once a constant is defined in configuration file we can call this all over the project without redeclaring this.
Generally a constant name has defined in upper case letter. We can also follow the same rule for the constant name as for variable except it doesn't have a leading dollar sign
PHP 7 provides feature to define array constant using define function.
This is the syntax of PHP Constant - define("CONSTANT_NAME", "CONSTANT_VALUE", "Case Sensitive");
We define a constant using define function.
"CONSTANT_NAME" is a string.
"CONSTANT_VALUE" is a PHP Expression.
"Case Sensitive" is optional. It is a Boolean value (true or false). By default it is true.
Example
<?php
define("SITE", "eTutorials Point");
echo SITE;
?>
Output :
eTutorials PointRelated PHP Functions
PHP array_reverse() functionPHP array_diff() function
PHP array_key_exists() function
PHP array_push() function
PHP array_search() function
PHP class_exists() function
PHP curl_setopt() function
PHP die() function
PHP dirname() function
PHP each() function
PHP explode() function
PHP file_exists() function
PHP function_exists() function
PHP getenv() function
PHP is_readable() function
PHP ksort() function
PHP mkdir() function
PHP ob_start() function
PHP parse_url() function
PHP str_repeat() function
PHP substr() function