Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PHP

replace key name in associative array

function change_key( $array, $old_key, $new_key ) {

    if( ! array_key_exists( $old_key, $array ) )
        return $array;

    $keys = array_keys( $array );
    $keys[ array_search( $old_key, $keys ) ] = $new_key;

    return array_combine( $keys, $array );
}
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #replace #key #associative #array
ADD COMMENT
Topic
Name
7+6 =