PHP用Array模拟枚举

C#中枚举Enum的写法:

/// <summary>
/// 公开类型 2-好友可见 1-公开 0-不公开
/// </summary>
public enum OpenStatusWithFriend
{
/// <summary>
/// 不公开
/// </summary>
Close = ,
/// <summary>
/// 公开
/// </summary>
Open = ,
/// <summary>
/// 好友可见
/// </summary>
Friend =
}

PHP中没有枚举类型,用Array来模拟表示:

public class testInfo
{
//公开类型
public static $OpenStatusWithFriend = array (
//不公开
'Close' => 0,
//公开
'Open' => 1,
//好友可见
'Friend'=>2
);
}

PHP访问:

$openType = testInfo::$OpenStatusWithFriend['Close'];
上一篇:面试题:Nginx负载均衡的算法怎么实现的?为什么要做动静分离?


下一篇:Nginx负载均衡+监控状态检测