PHP

PHP Constants

Constants are variables
Constants are variables except that once they are defined they can’t be changed or undefined.

  • A constant is an identifier (name) for a simple value. The value cannot be changed during the script.
  • A valid constant name starts with a letter or underscore.
  • (no $ sign before the constant name).
  • Note: Unlike variables, constants are automatically global across the entire script.

Create a PHP constant

  • You can create a constant by using the define () function.
  • Use the define function to specify the name and value of a constant. (name, value, case-insensitive).
  • Many programmers use capital letters to name constants – so they stand out.
  • Note: Since a constant can not be change you do not use a $ sign before it’s name when you declare it or (use it).

 Parameters 

name: Specifies the name of the constant

value: Specifies the value of the constant

case-insensitive: Specifies whether the constant name should be case-insensitive. Default is false

How to declare constants
Examples:

PHP Constant Examples

Output: Welcome to PHPGURUKUL.com!

About the author

Anuj kumar

I'm Anuj kumar a web developer with 4+ year experience .I write blogs in my free time. I love to learn new technologies and share with others. I founded PHPGurukul in September 2015. The main aim of this website to is provide php , jquery , mysql , phpoops and other web development tutorials. I am trying best effort to make PHPGurukul useful for every single moment spend on this website. If you think this website is useful to visit please share with your friend and buddies.

Leave a Comment