<?php
function array_replace_key( & $arr , $old , $new , $overwrite = true ) : bool {
if ( isset ( $arr [ $new ] ) and
! $overwrite ) { return false ;
}
$arr [ $new ] = $arr [ $old ] ;
return true ;
}
// Define o array que será modificado
$arr = [
'title' => 'Um título qualquer' ,
'description' => 'Descrição de alguma coisa qualquer'
] ;
// Substitui a chave desciption por descrição
array_replace_key( $arr , 'description' , 'descrição' ) ;
// Exibe o array
// Substitui a chave title por descrição, sem sobrescrita
array_replace_key( $arr , 'title' , 'descrição' , false ) ;
// Exibe o array
PD9waHAKCmZ1bmN0aW9uIGFycmF5X3JlcGxhY2Vfa2V5KCYkYXJyLCAkb2xkLCAkbmV3LCAkb3ZlcndyaXRlID0gdHJ1ZSk6IGJvb2wgewogICAgaWYgKGlzc2V0KCRhcnJbJG5ld10pIGFuZCAhJG92ZXJ3cml0ZSkgewogICAgICAgIHJldHVybiBmYWxzZTsKICAgIH0KCiAgICAkYXJyWyRuZXddID0gJGFyclskb2xkXTsKICAgIHVuc2V0KCRhcnJbJG9sZF0pOwoKICAgIHJldHVybiB0cnVlOwp9CgovLyBEZWZpbmUgbyBhcnJheSBxdWUgc2Vyw6EgbW9kaWZpY2FkbwokYXJyID0gWwogICAgJ3RpdGxlJyA9PiAnVW0gdMOtdHVsbyBxdWFscXVlcicsCiAgICAnZGVzY3JpcHRpb24nID0+ICdEZXNjcmnDp8OjbyBkZSBhbGd1bWEgY29pc2EgcXVhbHF1ZXInCl07CgovLyBTdWJzdGl0dWkgYSBjaGF2ZSBkZXNjaXB0aW9uIHBvciBkZXNjcmnDp8OjbwphcnJheV9yZXBsYWNlX2tleSgkYXJyLCAnZGVzY3JpcHRpb24nLCAnZGVzY3Jpw6fDo28nKTsKCi8vIEV4aWJlIG8gYXJyYXkKcHJpbnRfcigkYXJyKTsKCi8vIFN1YnN0aXR1aSBhIGNoYXZlIHRpdGxlIHBvciBkZXNjcmnDp8Ojbywgc2VtIHNvYnJlc2NyaXRhCmFycmF5X3JlcGxhY2Vfa2V5KCRhcnIsICd0aXRsZScsICdkZXNjcmnDp8OjbycsIGZhbHNlKTsKCi8vIEV4aWJlIG8gYXJyYXkKcHJpbnRfcigkYXJyKTs=