Home >Backend Development >PHP Problem >How to convert array key name (key) to lowercase in php
In PHP, you can use the array_change_key_case() function to convert the array key name (key) to lowercase; this function can convert all the keys (keys) in the array to lowercase letters, you only need to omit the first Two parameters or set the second parameter to "CASE_LOWER", the syntax is "array_change_key_case (array)" or "array_change_key_case (array, CASE_LOWER)".
The operating environment of this tutorial: windows7 system, PHP version 8.1, DELL G3 computer
How to convert the array key name (key) in php for lowercase? Simple!
PHP provides a function: array_change_key_case() to achieve this function. Let's take a look at this function
array_change_key_case() The function can convert all keys of the array into uppercase letters or lowercase letters. Syntax format:
array_change_key_case(array,case);
Description | |
---|---|
Required. Specifies the array to use. | |
Optional. Possible values: |
|
Implementation code:
<?php header('content-type:text/html;charset=utf-8'); $age=array("Peter"=>"35","Ben"=>"37","Joe"=>"43"); echo "原数组:"; var_dump($age); echo "数组键名(key)转为小写:"; var_dump(array_change_key_case($age)); var_dump(array_change_key_case($age,CASE_LOWER)); ?>Recommended learning: "
PHP video tutorial 》
The above is the detailed content of How to convert array key name (key) to lowercase in php. For more information, please follow other related articles on the PHP Chinese website!