- PHP

How to Fix “array_change_key_case() expects parameter 2 to be int” Warning in PHP?

This warning means that there is a problem with the second argument of this function.

Usually its caused by putting there a string and making something like this:

array_change_key_case($array, 'CASE_LOWER');

Instead of something like this:

array_change_key_case($array, CASE_LOWER);

Here is a full, working example you can adjust to your needs:

<?php
    $students = [
        "oscar" => 19,
        "frank" => 22,
    ];

    $students = array_change_key_case($students, CASE_UPPER);

    print_r($students);
?>

Output:

Array ( [OSCAR] => 19 [FRANK] => 22 )