PHP - Constants

PHP Constant is an identifier for a value like a variable but it has some unique characteristics such as,
  • Once you create a constant then you cant change it
  • Once you create a constant then you cant undefined it
  • Value cannot be changed during the  script
  • Constant Name starts with a Letter or underscore sign. There is no $ sign for constants.

How to set a PHP Constant
There is a key word calling "define" uses to define the constants in PHP.



Syntax:
define (<Constant Name>, <Value>, <true/false);
- 1st Parameter defines the name of the constant
- 2nd Parameter defines the value of the constant
- 3rd parameter is an optional to define whether the constant name is case sensitive or not, if case sensitive then uses true as the value.

Example:

Code:





Output:


2 comments:

  1. I appreciate you giving this fantastic information. It's pretty fascinating. Nowadays, a lot of sites I visit don't really offer anything that draws readers in, but yours does a terrific job of doing just that. There are many posts, however your writing style is excellent and knowledgeable. continue to provide such helpful information, and look at my website as well.
    Data Science Training Institute In Hyderabad

    ReplyDelete