- PHP

How to make all array keys lowercase in PHP?

You can do this with simple loop, but there is another, even simpler way.

PHP has its own array_change_key_case function that allows us to do so.

array_change_key_case($array, 'CASE_LOWER');

Example:

<?php
    $exampleArray = [
        "Animal" => "dog",
        "Name" => "Peter",
        "Size" => "Small",
    ];

    $exampleArray = array_change_key_case($exampleArray, CASE_LOWER);

    print_r($exampleArray);
?>