array_change_key_case


php128 apg

CHANGES the case of all keys in a given ARRAY.





This function returns an array with its keys lower or uppercased, or FALSE if $array is not an ARRAY.

This function may have problems with accented characters.



<?php

arr array_change_key_case 
arr $array [, int $case CASE_LOWER ] )


where,

$array The working array

$case To control whether lower or upper case

?>

 $array 


The working array.



 $case 


To control whether lower or upper case.

CASE
CONSTANT VALUE PURPOSE
CASE_LOWER 0 Change to lowercase
CASE_UPPER 1 Change to UPPERCASE
ed48


  1 EXERCISE   

<?php

$basearray01 
= ['continents' => 
                                  [
'South America''Europe''Asia'], 
                        
'countries' => 
                                  [
'Brasil''Portugal''Japan']];  

var_export($basearray01);

echo 
'<br>';

$key01 array_keys($basearray01);

echo 
'<br>';

var_export($key01);

echo 
'<br><br><br>';

$chgcase01 CASE_UPPER;

$basearray01a 
          
array_change_key_case($basearray01$chgcase01);

var_export($basearray01a);

echo 
'<br>';

$key01a array_keys($basearray01a);

echo 
'<br>';

var_export($key01a);

?>

 RESULT   


array ( 'continents' => array ( 0 => 'South America', 1 => 'Europe', 2 => 'Asia', ), 'countries' => array ( 0 => 'Brasil', 1 => 'Portugal', 2 => 'Japan', ), )

array ( 0 => 'continents', 1 => 'countries', )


array ( 'CONTINENTS' => array ( 0 => 'South America', 1 => 'Europe', 2 => 'Asia', ), 'COUNTRIES' => array ( 0 => 'Brasil', 1 => 'Portugal', 2 => 'Japan', ), )

array ( 0 => 'CONTINENTS', 1 => 'COUNTRIES', )

  2 EXERCISE   

<?php

$basearray02 
= ["EDforty-EIGHT" => "PHP"
                  
"edFORTY-eight" => "Apache"];

print_r($basearray02);

echo 
'<br>';

$key02 array_keys($basearray02);

echo 
'<br>';

print_r($key02);

echo 
'<br><br><br>';

$chgcase02 CASE_LOWER;

$basearray02a 
          
array_change_key_case($basearray02$chgcase02);

print_r($basearray02a);

echo 
'<br>';

$key02a array_keys($basearray02a);

echo 
'<br>';

print_r($key02a);

?>

 RESULT   


Array ( [EDforty-EIGHT] => PHP [edFORTY-eight] => Apache )

Array ( [0] => EDforty-EIGHT [1] => edFORTY-eight )

Array ( [edforty-eight] => Apache )

Array ( [0] => edforty-eight )


  3 EXERCISE   

<?php

$basearray03 
= array (=> array (37), => array (1113));

var_dump($basearray03);

echo 
'<br>';

$key03 array_keys($basearray03);

echo 
'<br>';

var_dump($key03);

echo 
'<br><br><br>';

$chgcase03 CASE_LOWER;

$basearray03a 
           
array_change_key_case($basearray03$chgcase03);

var_dump($basearray03a);

echo 
'<br>';

$key03a array_keys($basearray03a);

echo 
'<br>';

var_dump($key03a);

?>

 RESULT   

array(2) { [1]=> array(2) { [0]=> int(3) [1]=> int(7) } [2]=> array(2) { [0]=> int(11) [1]=> int(13) } }

array(2) { [0]=> int(1) [1]=> int(2) }


array(2) { [1]=> array(2) { [0]=> int(3) [1]=> int(7) } [2]=> array(2) { [0]=> int(11) [1]=> int(13) } }

array(2) { [0]=> int(1) [1]=> int(2) }


  4 EXERCISE   

<?php

$basearray04 
= array ("EDforty-EIGHT" => "PHP"
                  
"edFORTY-eight" => "Apache"
                  
"EDFORTY-EIGHT" => "MySQL" );

var_export($basearray04);

echo 
'<br>';

$key04 array_keys($basearray04);

echo 
'<br>';

var_export($key04);

echo 
'<br><br><br>';

$chgcase04 = -10.76;

$basearray04a 
          
array_change_key_case($basearray04$chgcase04);

var_export($basearray04a);

echo 
'<br>';

$key04a array_keys($basearray04a);

echo 
'<br>';

var_export($key04a);

?>

  5 EXERCISE   

<?php

$var05 
"EDforty-eight";

var_export($var05);

echo 
'<br>';

$chgcase05 0;

$var05a array_change_key_case($var05$chgcase05);

var_export($var05a);

echo 
'<br>';

$key05a array_keys($var05a);

echo 
'<br>';

var_export($key05a);

?>

 RESULT   

PHP 7.4.XX shows two Warning: ...,

PHP 8.0.XX just one Fatal error: ...

Try it, then.