hi all!
is there any way of changing an array key name without loosing its internal pointer position?
i've found some functions at php.net but they aren't useful on my case
thx in advance
changing key names
Moderator: General Moderators
hm...
something like this perhaps:
something like this perhaps:
Code: Select all
function rename_key($array, $from, $to) {
$keys = array_keys($array);
$vals = array_values($array);
$ret = array();
for($i = 0, $len = count($keys); $i<$len; $i++) {
if($keys[$i] == $from) $keys[$i] = $to;
$ret[ $keys[$i] ] = $vals[$i];
}
return $ret;
}