I want to create hierarchical Enumarations for my PHP applications and thought about things like
abstract class User_Roles extends Enum {
const Administrator = "";
const Account_Manager = "Administrator";
const BlogAuthor = "Account_Manager";
const CommentManager = "Account_Manager";
}
I am using this Enum-Class: stack overflow
So, every child has a parent Node as its value.
Here is how I did it:
$constants = $reflector->getConstants();
foreach ($constants as $key => $value) {
if ($value == "") {
$returnHierarchy[$key] = array();
continue;
}
$returnHierarchy[][$value] = $key;
}
But I have some problems with the multidimensional array that I want to create.
So it should look like this:
[Administrator]
{
[Account_Manager]
{
[BlogAuthor]
[CommentManager]
}
}
But in the end I get things like this:
array(4) (
[Administrator] => array(0)
[0] => array(1) (
[Administrator] => (string) Account_Manager
)
[1] => array(1) (
[Account_Manager] => (string) BlogAuthor
)
[2] => array(1) (
[Account_Manager] => (string) CommentManager
)
)
Is there something that I misunderstand or don’t notice?
source
share