Defining a Constant with PHP

Defining a constant in PHP can come in handy when working with a value that will be used throughout your script. What is a constant exactly? According to PHP.net, “A constant is an identifier (name) for a simple value“. One important thing you need to know is that, like its name states, a constant cannot be changed. That is pretty much the main difference between a constant and a variable.

Here is a basic example:


Simple enough. Just remember that constants are case sensitive, so this wouldn’t work:


Unless, of course, you set a third parameter within the define() function to control the case. By default, it is set to false, which is case-sensitive. To make it case-insensitive, all you need to do is set that third parameter to true.


Share this:

Email
Facebook
Twitter
Pinterest
Pocket

Premium Themes for WordPress

Looking for an easy-to-use Premium Theme for WordPress? Check out Themes by bavotasan.com and have your site up and running in no time.

Use this WordPress website builder to build powerful websites in no time for your or your clients.

WordPress Hosting

WP Engine – designed from the ground-up to support and enhance the workflow of web designers.

Bluehost – providing quality web hosting solutions since 1996.

About the author

Picture of Luke Perrie

Luke Perrie