Apart from the above answers -- the following code also does the trick. The benefit is you can use this for any operation on the keys
than only making the keys uppercase
.
<?php
$arr = array(
"key1" => "value",
"key2" => "value2"
);
echo "<pre>";print_r($arr);echo "</pre>";
$arra = array_combine(
array_map(function($k){
return strtoupper($k);
}, array_keys($arr)
), $arr);
echo "<pre>";print_r($arra);echo "</pre>";
This code outputs as:
Array
(
[key1] => value
[key2] => value2
)
Array
(
[KEY1] => value
[KEY2] => value2
)
So this is just an alternative and more generic solution to change keys
of an array.
Thanks.