TUTSCODE PHP 006: PHP CONSTANTS IN


Posted on 2015-07-08 08:43:15


In PHP, the constant is used to indicate the value has not changed and can not be edited during runtime. 1. Declare constants in PHP - The name does not have the character constant $ at the top. - People often use capital letters to name constants. Examples CONST_DEV. - Defines a constant user define functions. This function takes three parameters: + The first argument: the name of the constant. + 2nd parameter: the value of the constants. + 3rd parameter: true or false. This parameter is passed on to decide if there is constant discrimination case sensitive or not. The default value of this parameter is false. For example:
1
define('CONST_DEV', 1);
To know the effect of parameters define the function 3rd you can run the following script:
1
define('DEV_NAME',  1,  true);<br /><br />echo dev_name;
- The value of a constant can only be attached to one of the basic data types: boolean, integer, float, string. 2. How to use After declaring one can use directly by calling its name:
1
2
define('CONSTANT_NAME', 'dev');
Echo CONSTANT;
Note: constant no $ characters at the top. You could read more PHP at http://tutscode.com/category/programming-language/php-programming-language