PHP/Math/define
Constants and switch statement
<source lang="html4strict">
<?php define("ALIGN_LEFT", 1); define("ALIGN_CENTER", 2); define("ALIGN_RIGHT", 3);
switch($value) {
case ALIGN_LEFT : break; case ALIGN_CENTER : break; case ALIGN_RIGHT : break;
} ?>
</source>
Constants, like the names of variables, are case-sensitivebut unlike variables
<source lang="html4strict">
They do not start with a dollar sign. You can change this behavior by passing true as a third parameter to define( ), which makes the constant case-insensitive: <?
define("SecondsPerDay", 86400, true); print SecondsPerDay; print SECONDSperDAY;
?>
</source>
Define a constant as an array or object
<source lang="html4strict">
<?php $arr = array("apple", "orange", "pear"); define("MYARRAY", serialize($arr)); function MyTest() {
print_r(unserialize(MYARRAY));
} MyTest(); ?>
</source>