Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / PHP

array_change_key_case()

Normalize associative column names before looking them up.

Version: PHP 8.4; repository runtime, production runtime not attested

Syntax

array_change_key_case(array $array, int $case = CASE_LOWER): array

Normalize associative column names before looking them up. The function changes string keys to lower or upper case and preserves integer keys and values. If two keys become the same string, the later value overwrites the earlier one. This operation changes only the top level.

Signature

array_change_key_case(array $array, int $case = CASE_LOWER): array

Example output

{"id":9,"4":"raw"}

Examples

<?php
$fields = ['ID' => 7, 'id' => 9, 4 => 'raw'];
echo json_encode(array_change_key_case($fields, CASE_LOWER));

Result

{"id":9,"4":"raw"}

Sources