How to convert array values to lowercase in PHP?

user1163513 picture user1163513 · Jun 13, 2012 · Viewed 108.2k times · Source

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

Something like array_change_key_case?

Answer

ariefbayu picture ariefbayu · Jun 13, 2012

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);
}