Last active
January 2, 2020 12:22
-
-
Save zaqihsn/5fe70c77445e7baeeef793e4d182026f to your computer and use it in GitHub Desktop.
Remove array prefix or add prefix
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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