Skip to content

Instantly share code, notes, and snippets.

@zaqihsn
Last active January 2, 2020 12:22
Show Gist options
  • Save zaqihsn/5fe70c77445e7baeeef793e4d182026f to your computer and use it in GitHub Desktop.
Save zaqihsn/5fe70c77445e7baeeef793e4d182026f to your computer and use it in GitHub Desktop.
Remove array prefix or add prefix
function change_array_keys($prefix='',$remove='',$array){
if(count($array)>0){
$temp =array();
if($remove!='')
foreach($array as $k=>$val){
$key = str_replace($remove,$prefix,$k);
$temp[$key] = $val;
}
else
foreach($array as $k=>$val){
$key = $prefix.$k;
$temp[$key] = $val;
}
return $temp;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment