Skip to content

normalizeWhere

Corey Avis edited this page Sep 23, 2026 · 2 revisions

normalizeWhere [Protected]

Processes and converts key-value pairs, indexed arrays, and fully-keyed associative arrays into a uniform format to simplify downstream SQL generation. Used within the andWhere and orWhere methods.

Usage

normalizeWhere(array $array = []): array

Parameters

array (array) : The multi-dimensional array containing supported input formats.

Each element must follow one of the three supported structures:

1️⃣ Key-Value Pair: An associative array where the key is the column and the value is the value. Uses the default = operator. (ex. ['user' => 'name'])

2️⃣ Indexed Array: A numerically indexed array representing column, value and op (in that order). The 3rd value is optional and defaults to =. (ex. ['qty', 10, '>'] or ['user', 'name'])

3️⃣ Full Associative Array: A formal array using explicit column, value, and op keys. (ex. ['column' => 'user', 'value' => 'name', 'op' => '<>'])

Return Value

(array) : Returns the uniform array.

Examples

$db->normalizeWhere(['id' => 12])
// Result: ['column' => 'id', 'value' => 12, 'op' => '=']

$db->normalizeWhere(['qty', 10, '>'])
// Result: ['column' => 'qty', 'value' => 10, 'op' => '>']

Debug Errors

  • Logs a notice if no array is present.

Related Methods

where | andWhere | orWhere | whereGroup | whereStr


Home | CoreyDB | Helpers

Clone this wiki locally