Oihana PHP Enums

Order uses ConstantsTrait

Enumeration of sorting direction values, often used in SQL, data queries, or collection sorting.

This class provides both lower-case and upper-case variants of common sorting keywords:

  • asc, ASC: Ascending order
  • desc, DESC: Descending order

Example usage:

use oihana\enums\Order;

$query = 'SELECT * FROM users ORDER BY name ' . Order::ASC;

You may want to normalize user input or validate sorting directions using helper methods.

Tags
author

Marc Alcaraz (ekameleon)

since
1.0.0

Table of Contents

Constants

asc  : string = 'asc'
The ascending order (lower case).
ASC  : string = 'ASC'
The ascending order (upper case).
desc  : string = 'desc'
The descending order (lower case).
DESC  : string = 'DESC'
The descending order (upper case).

Methods

normalize()  : string|null
Returns the canonical order keyword ("ASC" or "DESC") from a case-insensitive input.

Constants

asc

The ascending order (lower case).

public string asc = 'asc'

ASC

The ascending order (upper case).

public string ASC = 'ASC'

desc

The descending order (lower case).

public string desc = 'desc'

DESC

The descending order (upper case).

public string DESC = 'DESC'

Methods

normalize()

Returns the canonical order keyword ("ASC" or "DESC") from a case-insensitive input.

public static normalize(string $value) : string|null
Parameters
$value : string

The order string.

Return values
string|null

The normalized value (e.g., "ASC", "DESC") or null if invalid.

On this page

Search results