Code Monkey home page Code Monkey logo

Comments (5)

BenSampo avatar BenSampo commented on May 31, 2024

You can use the getValues() function to get an array of all the values.

Is that what you're after?

from laravel-enum.

akos-vomo avatar akos-vomo commented on May 31, 2024

No, I'm talking about an associative array where the keys are the defined constant names, and the values are the constant values.
Simple example:

final class UserGender extends Enum
{
    const Female = 'F';
    const Male = 'M';
}

and then calling UserGender::toArray() would return

[
  'Female' => 'F',
  'Male' => 'M'
]

It's the exact same functionality you implemented in the Enum::getConstants() method. But that method is not public. That's why I wrote it should be either public, or there should be a public accessor method like e.g. Enum::toArray().

(Btw, of course I could do something like this in the current status, but it's ugly and ineffective: )

array_combine(Enum::getKeys(),Enum::getValues())

from laravel-enum.

BenSampo avatar BenSampo commented on May 31, 2024

Thanks for clarifying @akos-vomo, I do see what you mean now. I'll add this in.

from laravel-enum.

akos-vomo avatar akos-vomo commented on May 31, 2024

👍 Thank you @BenSampo . Feel free to close this issue after.

from laravel-enum.

BenSampo avatar BenSampo commented on May 31, 2024

Fixed

42a3a97

from laravel-enum.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.