PHP/Math/define
Constants and switch statement
<?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;
}
?>
Constants, like the names of variables, are case-sensitivebut unlike variables
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;
?>
Define a constant as an array or object
<?php
$arr = array("apple", "orange", "pear");
define("MYARRAY", serialize($arr));
function MyTest() {
print_r(unserialize(MYARRAY));
}
MyTest();
?>