UnitEnum::cases

(PHP 8 >= 8.1.0)

UnitEnum::casesGenerates a list of cases on an enum

Beschreibung

public static UnitEnum::cases(): array

This method will return a packed array of all cases in an enumeration, in lexical order.

Parameter-Liste

Diese Funktion besitzt keine Parameter.

R├╝ckgabewerte

An array of all defined cases of this enumeration, in lexical order.

Beispiele

Beispiel #1 Basic usage

The following example illustrates how enum cases are returned.

<?php
enum Suit
{
    case 
Hearts;
    case 
Diamonds;
    case 
Clubs;
    case 
Spades;
}

var_dump(Suit::cases());
?>

Das oben gezeigte Beispiel erzeugt folgende Ausgabe:

array(4) {
    [0]=>
    enum(Suit::Hearts)
    [1]=>
    enum(Suit::Diamonds)
    [2]=>
    enum(Suit::Clubs)
    [3]=>
    enum(Suit::Spades)
}
add a note add a note

User Contributed Notes

There are no user contributed notes for this page.
To Top