phparraysstringlowercase

How to convert array values to lowercase in PHP?


How can I convert all values in an array to lowercase in PHP?

Something like array_change_key_case?


Solution

  • use array_map():

    $yourArray = array_map('strtolower', $yourArray);
    

    In case you need to lowercase nested array (by Yahya Uddin):

    $yourArray = array_map('nestedLowercase', $yourArray);
    
    function nestedLowercase($value) {
        if (is_array($value)) {
            return array_map('nestedLowercase', $value);
        }
        return strtolower($value);
    }