Constant: constant means which is not going to change. Mainly we use constant to declare a variable which is not going to change. for example to see the config file path.
You can define a constant by using the define()-function or by using the const keyword outside a class definition as of PHP 5.3.0.
Following are the way to set and get the constant value.
Above CONFIG_FILE_PATH is constant, it is available in throughout the page. but it cannot be re-declare.
Following things keep in mind regarding this topic(Minimum)
You can define a constant by using the define()-function or by using the const keyword outside a class definition as of PHP 5.3.0.
Following are the way to set and get the constant value.
/** set the constant**/ define('CONFIG_FILE_PATH','/config'); /** set the constant**/ /** get the constant**/ echo CONFIG_FILE_PATH; /** get the constant**/
Above CONFIG_FILE_PATH is constant, it is available in throughout the page. but it cannot be re-declare.
Following things keep in mind regarding this topic(Minimum)
- PHP constants Array
- PHP constants Class
- Use of define, constant etc
- How to check a variable defined or not
- How to check a constant is exist of not
No comments:
Post a Comment