note 59252 deleted from function.define by tularis
| From: | tularis@php.net | Date: | Sun, 03 Jun 2007 09:40:28 +0000 |
| Subject: | note 59252 deleted from function.define by tularis | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-127152@lists.php.net to get a copy of this message | ||
Note Submitter: some at user dot com
----
My hack at constant arrays :
function carray($const = null, $index = null)
{
static $carrays;
if ($const === null)
{
$i = count($carrays);
$carrays[$i] = $index;
return $i;
} else
{
return $index === null ? $carrays[$const] : $carrays[$const][$index];
}
}
function aconst()
{
$args = func_get_args();
if (count($args) == 1 && is_array($args[0]))
{
return carray(null, $args[0]);
} else
{
return carray(null, $args);
}
}
Use like this:
define('NRWORDS', aconst('zero', 'one', 'two',
'three'));
define('STUNT_DESC', aconst(array(
STUNT_TWOWHEELS => 'Two wheels',
STUNT_WHEELIE => 'Wheelie',
STUNT_STOPPIE => 'Stoppie'
)));
print(carray(NRWORDS, 2));
print(carray(STUNT_DESC, STUNT_WHEELIE));
$arr = carray(STUNT_DESC);
print_r($arr[STUNT_STOPPIE]);
bvr.