Creating Constants

A constant is created with the define function, giving it the name of the constant and the value you want to assign to it. The name of the constant is always quoted, but the value you assign to the constant is only quoted if it's a string. The value of a constant cannot be altered. You don't prefix the constant with a $ when used.

<html>
<head>
<title>Creating Constants</title>
<meta Name="Author" Content="Hann So">
</head>
<body>
<p>
<?php
define ("year", 2008);
define ("hello", "Hello World");
echo hello," ", year;
</p>
</body>
</html>

View the effect


Variables | Identifiers | What are Variables? | Assigning Values to Variables | Data Types | Variable Scope | Interpolating Variables in Strings | Creating Variables Variables | Creating Constants
© 2008: Hann So
email: hso@voyager.deanza.edu