search
HomeBackend DevelopmentPHP ProblemHow 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)".

How to convert array key name (key) to lowercase in php

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);
##ParametersDescriptionarrayRequired. Specifies the array to use. caseOptional. Possible values:
    CASE_LOWER - Default value. Convert an array's keys to lowercase letters.
  • CASE_UPPER - Convert array keys to uppercase letters.
Return value: Returns an array with keys with lowercase letters, or returns an array with keys with uppercase letters, or if array is not a Array returns FALSE.


alright! After understanding the array_change_key_case() function, we also know how to convert the array key name (key) to lowercase:

  • Just need to set the second parameter of the array_change_key_case() function to " CASE_LOWER", or omit the second parameter.

Implementation code:

<?php
header(&#39;content-type:text/html;charset=utf-8&#39;);  
$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));
?>

How to convert array key name (key) to lowercase in php

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!

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools

SublimeText3 Linux new version

SublimeText3 Linux new version

SublimeText3 Linux latest version

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Atom editor mac version download

Atom editor mac version download

The most popular open source editor

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools