Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Change array keys in LOWER or UPPER case

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 110
    Comment on it

    Hello friends,

    If you want to change the array keys in either upper case or lower case then you can use a predefined array function of PHP which is "array_change_key_case()". array_change_key_case returns an array with all keys from array lower or upper cased. Numbered indices are left as is.

    Parameters: array: The array to work on case: Either CASE_UPPER or CASE_LOWER (default) Here is some example which will explain you clearly-

    <?php
    $inputArray = array("First" => 1, "Second" => 2);
    print_r(array_change_key_case($inputArray, CASE_UPPER));
    ?>
    

    Output:

    Array
    (
        [FIRST] => 1
        [SECOND] => 2
    )
    

    Here in another lower case example-

    <?php
    $inputArray = array("First" => 1, "Second" => 2);
    print_r(array_change_key_case($inputArray, CASE_LOWER));
    ?>
    

    Output:

    Array
    (
        [first] => 1
        [second] => 2
    )
    

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: