Compare Enums | enum | Spatie

 SPATIE

enum
====

spatie.be/open-source

  [Docs](https://spatie.be/docs)  [Enum](https://spatie.be/docs/enum/v2)  Usage  Compare Enums

 Version   v3   v2   v1

 Other versions for crawler [v3](https://spatie.be/docs/enum/v3) [v2](https://spatie.be/docs/enum/v2) [v1](https://spatie.be/docs/enum/v1)

- [ Introduction ](https://spatie.be/docs/enum/v2/introduction)
- [ Postcardware ](https://spatie.be/docs/enum/v2/postcardware)
- [ Installation and setup ](https://spatie.be/docs/enum/v2/installation-and-setup)
- [ Questions &amp; issues ](https://spatie.be/docs/enum/v2/questions-and-issues)
- [ Changelog ](https://spatie.be/docs/enum/v2/changelog)
- [ About us ](https://spatie.be/docs/enum/v2/about-us)

Usage
-----

- [ Enum Setup ](https://spatie.be/docs/enum/v2/usage/enum-setup)
- [ Make Enum ](https://spatie.be/docs/enum/v2/usage/make-enum)
- [ Enum Methods ](https://spatie.be/docs/enum/v2/usage/enum-methods)
- [ Compare Enums ](https://spatie.be/docs/enum/v2/usage/compare-enums)

      You are viewing the documentation for **an older version** of this package. You can check the version you are using with the following command:

 `                                    composer show spatie/enum                                                                                                                                                                                                                                    `

Compare Enums
=============

###  On this page

1. [ Check if enums are equal ](#content-check-if-enums-are-equal)
2. [ Check if enum is one of ](#content-check-if-enum-is-one-of)
3. [ Check if enum is specific one ](#content-check-if-enum-is-specific-one)

Check if enums are equal
--------------------------------------------------------------------------------------------------------------------------------

Equality enums mean that their values are identical.

```
WeekDayEnum::monday()->isEqual(5); // false
WeekDayEnum::monday()->isEqual('monday'); // true
WeekDayEnum::monday()->isEqual('Montag'); // true
WeekDayEnum::monday()->isEqual(WeekDayEnum::tuesday()); // false
```

Check if enum is one of
-----------------------------------------------------------------------------------------------------------------------------

```
WeekDayEnum::monday()->isAny(['monday', 0, WeekDayEnum::tuesday()]); // true
```

Check if enum is specific one
-----------------------------------------------------------------------------------------------------------------------------------------------

You can use the magic `isXyz()` methods and add the to the doc-block for code-completion. There are two options for these magic methods static and non-static.

```
WeekDayEnum::isMonday(5); // false
WeekDayEnum::isMonday('monday'); // true
WeekDayEnum::isMonday('Montag'); // true
WeekDayEnum::tuesday()->isMonday(); // false
```
