Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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,700 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.