[go: nahoru, domu]

Voting

: four plus four?
(Example: nine)

The Note You're Voting On

Shaun H
16 years ago
I saw that PHP doesn't have an enum function so I created my own. It's not necessary, but can come in handy from time to time.

<?php
function enum()
{
$args = func_get_args();
foreach(
$args as $key=>$arg)
{
if(
defined($arg))
{
die(
'Redefinition of defined constant ' . $arg);
}

define($arg, $key);
}
}

enum('ONE','TWO','THREE');
echo
ONE, ' ', TWO, ' ', THREE;
?>

<< Back to user notes page

To Top