O'Reilly logo

PHP for Teens by Maneesh Sethi

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Constants

Constants are an important concept to learn because they can make your programs a lot safer. Imagine a program that converts hours into days. You might have a hoursPerDay constant that always equals 24. You can define constants, but once they are defined they can never be redefined or undefined. Unlike variables, constants never change throughout the entire program. Use constants whenever, for instance, you have a value you want to multiply all inputs by or a known natural constant such as pi. Because the program cannot change the constant’s value, it is guaranteed to work correctly.

You define constants differently than you do variables. With variables, you simply do something like this:

$variable = value;

You can change the value ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required