How to convert array values to lowercase in PHP?

How to convert array values to lowercase in PHP?

  1. Blog
  2. 15 November 2026
  3. 3 min read

Stefan Bogdanescu

Founder & Senior Architect

Converting Array Values to Lowercase in PHP

When you need to normalize data for comparison, storage, or display, converting array values to lowercase is a frequent requirement. The immediate instinct might be to reach for array_change_key_case, but that function operates on keys, not values. It transforms the associative keys of an array into their lower-case equivalents while preserving the original values. If your goal is to modify the data held within the array rather than the structure itself, using this function will result in incorrect behavior and wasted logic.

To actually transform the string values inside an array, you must iterate through the collection and apply a case-changing function to each element. PHP provides several built-in options for this, each with specific use cases regarding how they handle characters outside the standard ASCII range.

The Standard Approach: strtolower

The most common and efficient method is using array_map() combined with strtolower(). This functional approach creates a new array where every value has been processed without modifying the original data structure.

$data = ['Name' => 'John', 'City' => 'New York'];

$lowerData = array_map('strtolower', $data);

// Result: ['name' => 'john', 'city' => 'new york']

This pattern is clean and readable. It relies on the fact that array_map accepts a callable as its first argument, allowing you to pass the string function directly. If you are using PHP 8.0 or later, you can also use an arrow function for slightly improved readability:

$lowerData = array_map(fn($val) => strtolower($val), $data);

This approach is generally preferred because it avoids explicit loops and keeps the transformation logic isolated.

Handling Special Characters: mb_strtolower

A critical pitfall in text processing occurs when dealing with UTF-8 strings containing accented characters, such as é, ñ, or ü. The standard strtolower() function treats these characters as ASCII. While it may convert some letters, it often fails to handle locale-specific rules correctly, potentially resulting in garbled output or incomplete normalization depending on the character set encoding.

For applications dealing with international data, you should use mb_strtolower(). This function respects multi-byte characters and ensures that accented letters are converted to their lowercase equivalents according to Unicode standards.

$data = ['Café' => 'Bistro', 'Niño' => 'School'];

$lowerData = array_map('mb_strtolower', $data);

// Result: ['café' => 'bistro', 'niño' => 'school']

Always ensure the intl extension is loaded if you are relying heavily on locale-specific collation, though mb_strtolower usually suffices for simple case conversion tasks.

Modifying Arrays In Place

Sometimes memory efficiency or code simplicity dictates that you want to mutate the original array rather than creating a copy. You can achieve this by combining array_walk() with strtolower(). This function executes a callback for every element in an array and passes the value, the key, and the array itself by reference.

$data = ['Name' => 'John', 'City' => 'New York'];

array_walk($data, fn(&$value) => $value = strtolower($value));
// Note: Keys remain unchanged in this specific example as they are strings, 
// but if keys were numeric or you needed to change them, array_change_key_case would be relevant.

While array_walk is powerful, be cautious about side effects. If your callback logic relies on the original value being present for calculations elsewhere in the code, modifying it in place can introduce subtle bugs. Prefer returning a new array when testability and immutability are priorities.

Performance Considerations

For massive datasets, function overhead becomes relevant. array_map is implemented in C within the PHP core and is highly optimized. It typically outperforms explicit foreach loops written in pure PHP logic because it avoids the interpreter loop overhead for each iteration. When scaling to millions of records, sticking to built-in functions like array_map or array_walk ensures you are leveraging the engine's internal optimizations rather than reinventing the wheel with manual loops.

If you find yourself needing this functionality within a Laravel application, checking your service layer or utility classes is often more maintainable than scattering this logic across controllers. If your stack relies on custom packages for data normalization, ensure they adhere to these core PHP standards to avoid compatibility issues down the line.

Our network