Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

PHP PHP Basics (Retired) PHP Conditionals & Loops For Loops

jinhwa yoo
jinhwa yoo
10,042 Points

I have a question if you tell me define("USE_FULL_NAME", TRUE); define("MAX_BADGES", 20); define--->???

define("USE_FULL_NAME", TRUE); define("MAX_BADGES", 20);

define => what does this mean???/

2 Answers

Create a constant (Name of the constant , Value of the constant);

Joshua Mclendon
Joshua Mclendon
46,708 Points

Define is PHP's way of letting it know you're defining a constant variable. Constants are useful because they cannot be changed or modify with in other parts of the code. In Java we use final to declare a constant just as define is in PHP. The first parameter after the define keyword is the name you want your constant to be called. It is good practice to have this name in all caps so you know it is a constant when reading your code. The second parameter is the type of constant you want it to be (such as integer, boolean, string, or any other data type value).

For example is you have a program which calculates how much pay you will get in a pay period your pay per hour is something that doesn't continuously change, usually only if you get a promotion or raise, so declaring your PAY_PER_HOUR as a constant is a good idea. Plus this will help if you make a mistake and accidentally set PAY_PER_HOUR in the middle of your program to something it's not meant to be because the fact that it is a constant will not be influenced by that mistake because once declared (define) constants are un-changeable unless changed in the declaration itself.

Hope this helps friend.