Monday, July 31, 2017

PHP Constants


PHP constants are name or identifier that can't be changed during the execution of the script. PHP constants can be defined as define ().

A valid constant name starts with a letter or underscore (no $ sign before the constant name).






Defining PHP Constant :

Let's see the Syntax of php constant using define()
define(name, value, case-insensitive)
  1. name: specifies the constant name
  2. value: specifies the constant value
  3. case-insensitive: Default value is false. It means it is case sensitive by default.
The example below creates a constant with a case-sensitive name:

Example :1
<?php
define("DATABASENAME", "MYSQL SERVER DB");
echo DATABASENAME;
?>

Output :
-----------------
MYSQL SERVER DB

Example : 2
<?php
define("DATABASENAME", "MYSQL SERVER DB",false);
echo DATABASENAME;
?>

Output :
-----------------
MYSQL SERVER DB

The example below creates a constant with a case-insensitive name:

Example : 1
<?php
define("DATABASENAME", "MYSQL SERVER DB",true);
echo databasename;
?>

Output :
-----------------
MYSQL SERVER DB



No comments:

Post a Comment