PHPackages                             yuanzhihai/think-enum - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. yuanzhihai/think-enum

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

yuanzhihai/think-enum
=====================

更方便地在项目中定义并使用枚举

v2.0.0(2y ago)2691MITPHPPHP &gt;=8.1.0

Since Oct 13Pushed 2y ago1 watchersCompare

[ Source](https://github.com/yuanzhihai/think-enum)[ Packagist](https://packagist.org/packages/yuanzhihai/think-enum)[ RSS](/packages/yuanzhihai-think-enum/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (3)DependenciesVersions (5)Used By (1)

介绍
--

[](#介绍)

`think-enum` 主要用来扩展项目中的枚举使用，通过合理的定义枚举可以使代码更加规范，更易阅读和维护。 php8.1 版本后内置枚举支持，更多信息可以查看：

概览
--

[](#概览)

- 扩展原生的 BackedEnum，支持多语言描述
- 提供更多种实用的方式来实例化枚举、枚举 name、value 取值
- 提供了便捷的比较方法`is`、`isNot`和`in`，用于枚举实例之间的对比
-

安装
--

[](#安装)

PHP版本：php8.1+ 支持 thinkphp 8以上版本：

```
$ composer require yuanzhihai/think-enum ^2.0
```

更为具体的使用可以查看测试用例

### 常规使用

[](#常规使用)

- 定义

```
