我想要遍历枚举:
enum Shapes
{
case RECTANGLE;
case SQUARE;
case CIRCLE;
case OVAL;
}
如果我这样做,会得到 Shapes
常量未定义的错误:
foreach (Shapes as $shape) { }
我想到的最好解决方案是手动创建枚举数组:
$shapes = [
Shapes::RECTANGLE,
Shapes::SQUARE,
Shapes::CIRCLE,
Shapes::OVAL,
];
foreach ($shapes as $shape) { }
有没有更好的方式遍历枚举?