PHPackages                             labrodev/php-enum-mapper - 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. labrodev/php-enum-mapper

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

labrodev/php-enum-mapper
========================

PHP utility class for formatting Enums and to treat the cases as arrays

v1.0.0(1y ago)071MITPHPPHP &gt;=8.1

Since Oct 1Pushed 1y ago1 watchersCompare

[ Source](https://github.com/labrodev/php-enum-mapper)[ Packagist](https://packagist.org/packages/labrodev/php-enum-mapper)[ Docs](https://github.com/labrodev/php-enum-mapper)[ RSS](/packages/labrodev-php-enum-mapper/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (2)Versions (2)Used By (0)

Description
===========

[](#description)

PhpEnumMapper is a PHP utility class that provides methods to transform and map Enum cases into arrays of values, labels, or attributes. This utility is especially useful when dealing with Enums in contexts like forms, filters, or any view-related data where Enum values and labels are required.

Enums in PHP (introduced in PHP 8.1) can be quite powerful, but there are scenarios where you need to convert them into more usable formats, such as arrays for rendering. PhpEnumMapper makes it easy to convert Enums into different formats by allowing you to extract either their values or customized labels.

This utility includes two main static methods:

- keyValues: Converts Enum cases into a keyed array based on their values and specified attributes.
- keys: Extracts the underlying values from a set of Enum cases.

Installation
------------

[](#installation)

To install the package, run the following command in your Laravel project:

```
composer require labrodev/php-enum-mapper
```

Requirements
------------

[](#requirements)

- PHP 8.1 or higher

Configuration
-------------

[](#configuration)

After installing the package, no additional configuration is needed to start using utility.

Usage
-----

[](#usage)

To use the utility, use Utility class in your class and just call existed static methods from it:

```
