Free cookie consent management tool by TermsFeed Generator PHP array change key case | Amir Kamizi
AMIR KAMIZI
Home Blog Courses Books Newsletter Store Membership Buy me a coffee
PHP array change key case

PHP array change key case

Last Updated on Feb 14, 2023

Introduction

Sometimes you might change the case of the keys in your array. Maybe you want to have consistency of data, maybe you want to convert it to json and you want it to be the same format.

For whatever reason, it does not matter, it’s very easy to do that.

Array Change Key Case

You can pass your array to array_change_key_case

array_change_key_case(array,case)

The first argument is your array

And the second argument is CASE_UPPER or CASE_LOWER. Default is CASE_LOWER

It’s a very useful function especially when you load your data to an associative array from another source and the keys are not consistent.

In an associative array you should get the value by key and if the key is not consistent in being lower or uppercase it would be annoying to remember all of that.

We can easily use that function and fix it

Let’s see an example

$array = ["twiTteR"=> 63, "PrathUm" => 891, "AmiR" => 47];
array_change_key_case($array, CASE_UPPER);
// Array (
//  [TWITTER] => 63
//  [PRATHUM] => 891
//  [AMIR] => 47
// )

Conclusion

Now you know about array change key case in PHP.

I recommend you to open a PHP files define arrays with different key cases. Then try to use this function to change all of them to lower or upper case.

If you have any suggestions, questions, or opinions, please contact me. I’m looking forward to hearing from you!

Key takeaways

  • array change key case in php
  • lower case arrays keys
  • upper case array keys

Category: programming

Tags: #php #array

Join the Newsletter

Subscribe to get my latest content by email.

I won't send you spam. Unsubscribe at any time.

Related Posts

PHP function
Mar 21, 2023 programming

PHP function

Today we are going to learn about functions in PHP. Functions are very important because they can help you divide your application in small bites that can be handled with a function. ...

10 Min Read Read More
PHP Abstract Class
Mar 22, 2023 programming

PHP Abstract Class

Today we are going to talk about abstract classes in PHP. Abstract class is another important topic in object oriented programming and today we are going to learn everything about them. ...

8 Min Read Read More
PHP Array Sort
Feb 14, 2023 programming

PHP Array Sort

Today we are going to talk about sorting arrays in PHP. we will take a look at some of the most useful and common array sort functions in PHP and compare their functionality. ...

7 Min Read Read More
PHP Beginner to Advanced 2025: The Complete Guide to Mastering PHP and Building Modern Web Applications
Jul 17, 2025 programming

PHP Beginner to Advanced 2025: The Complete Guide to Mastering PHP and Building Modern Web Applications

PHP is often called the engine room of the modern web. Despite debates about newer technologies like Node.js, Go, or Python’s Django, PHP has remained a consistent favorite among developers. In fact, as of 2025, PHP powers over 75% of all websites that use a known server-side programming language. ...

9 Min Read Read More

Recommended Courses

Introduction to Machine Learning in PHP

Introduction to Machine Learning in PHP

Learn to Build Different Machine Learning Models Easily ...

PHP Tutorial Beginner to Advanced

PHP Tutorial Beginner to Advanced

Learn everything you need to start a successful career as a PHP developer ...