Constants are similar to variables (as they are used to store some data) but they have a fixed value: you cannot modify a constant after you have defined it.
In PHP constants can be defined by using the keyword define. It’s considered good practice to use uppercase names for constants.
define(‘CONSTANT_NAME’, ‘CONSTANT_VALUE’);
1 2 3 4 5 6 7 8 9 10 11 |
<?php #constants.php //defining a constant define("USERNAME", "John"); //using the constant echo "<p>Hello, <strong>" . USERNAME . "</strong>.</p>"; /* Hello, John. */ ?> |
Click here to read about if-else statements