Hello to all of you, thanks for landing on the TutorialPath.com, which is “Your Path to Learn Everything” in an easy way and you can learn almost every sort of important elements about online things. As you land here, so we can assume, you are a newbie for PHP Constants language, so you don’t need to worry about it.
Welcome to all our readers on our website at www.tutorialpath.com. As you all know that here on our website we will provide you lots of information related to the latest and newly introduced technology which help you to get updated with the latest tech. Here you will get all the useful information which is required in this tech world. As you know technology is one of the trending part in this world. So, here again we came up with a latest and new tech information which is related to the process of creating Basic PHP Constants for Beginners. With the help of this article you will get to know the complete process of how to create Basic PHP Constants for Beginners in a step by step manner. So, simply have a look to this article and grab all the useful information which is going to be very helpful for you.
What is Constant in PHP
- 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).
- Constants are used for data that is unchanged at multiple place within our program.
- Variables are temporary storage while Constants are permanent.
PHP constants can be defined by 2 ways:
- Using define() function
- Using const keyword
PHP constants follow the same PHP variable rules. For example, it can be started with letter or underscore only.
Conventionally, PHP constants should be defined in uppercase letters.
Syntax of constant:
Let’s see the syntax of define() function in PHP.
- name: specifies the constant name
- value: specifies the constant value
- case-insensitive: Default value is false. It means it is case sensitive by default.
PHP constant: const keyword
- The const keyword defines constants at compile time. It is a language construct not a function.
- It is bit faster than define().
- It is always case sensitive.