How To Define PHP Constant

In this article we will learn about how to define PHP Constant. 

PHP Constant

Constants are similar to variable. They hold information that can be accessed later, but once you define one, its value cannot be altered.
define(“ROOT_LOCATION”,”user/local/www”);

Things to remember when defining PHP constant


·         PHP constants are not preceded by a dollar sign.
·         You can define constants with a define function.
·         It is a good practice to define constants with upper case.

Predefined PHP constants

PHP comes ready made with many pre-declared constants. Few are known as Magic Constants.
Magic constants always have two underscore at the beginning and two at the end, so that you will not name your own constants with a name that is already taken.

 Example of php constants


echo “This”. __LINE__ . “ of file “ . __FILE__”;
Share on Google Plus

About Rahul Rana

I am an experienced web designer and SEO expert. I am running my own online marketing company i.e "SEO To Web Design". Thanks for reading, keep sharing online marketing and web design knowledge.
    Blogger Comment
    Facebook Comment

0 comments :

Post a Comment

Enter your email address:

Delivered by FeedBurner