wp_kses_array_lc()WP 1.0.0

Translates all keys of the specified array to lowercase (ABC to abc). Keys of nested arrays are also processed.

This works based on strtolower() function, so keys in Cyrillic are not handled correctly.

1 time — 0. sec (speed of light) | 50000 times — sec (speed of light)

No Hooks.

Returns

Array. Corrected array where all keys are lowercase.

Usage

wp_kses_array_lc( $inarray );
$inarray(array) (required)
The array whose keys must be converted to lowercase.

Examples

0

#1 Let's convert all keys of the array to lower case

$arr = wp_kses_array_lc(
	array(
		1 => 'foo',
		'ABC' => 'foo2',
		'КИРИЛЛИЦА' => array(
			'KEY' => 'Nested array'
		)
	)
);

print_r( $arr );

/* We get:
Array
(
	[1] => Array
		(
			[0] => foo
		)

	[abc] => Array
		(
			[0] => foo2
		)

	[КИРИЛЛИЦА] => Array
		(
			[key] => Nested array
		)

)
*/

Changelog

Since 1.0.0 Introduced.

wp_kses_array_lc() code WP 6.4.3

function wp_kses_array_lc( $inarray ) {
	$outarray = array();

	foreach ( (array) $inarray as $inkey => $inval ) {
		$outkey              = strtolower( $inkey );
		$outarray[ $outkey ] = array();

		foreach ( (array) $inval as $inkey2 => $inval2 ) {
			$outkey2                         = strtolower( $inkey2 );
			$outarray[ $outkey ][ $outkey2 ] = $inval2;
		}
	}

	return $outarray;
}