note 114654 added to function.array-replace
| From: | marvin_elia at web dot de | Date: | Tue, 18 Mar 2014 11:45:28 +0000 |
| Subject: | note 114654 added to function.array-replace | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-198955@lists.php.net to get a copy of this message | ||
Simple function to replace array keys. Note you have to manually select wether existing keys will be
overrided.
/**
* @param array $array
* @param array $replacements
* @param boolean $override
* @return array
*/
function array_replace_keys(array $array, array $replacements, $override = false) {
foreach ($replacements as $old => $new) {
if(is_int($new) || is_string($new)){
if(array_key_exists($old, $array)){
if(array_key_exists($new, $array) && $override === false){
continue;
}
$array[$new] = $array[$old];
unset($array[$old]);
}
}
}
return $array;
}
----
Server IP: 213.172.110.14
Probable Submitter: 84.46.96.242
----
Manual Page -- http://php.net/manual/en/function.array-replace.php
Edit -- https://master.php.net/note/edit/114654
Del: integrated -- https://master.php.net/note/delete/114654/integrated
Del: useless -- https://master.php.net/note/delete/114654/useless
Del: bad code -- https://master.php.net/note/delete/114654/bad+code
Del: spam -- https://master.php.net/note/delete/114654/spam
Del: non-english -- https://master.php.net/note/delete/114654/non-english
Del: in docs -- https://master.php.net/note/delete/114654/in+docs
Del: other reasons-- https://master.php.net/note/delete/114654
Reject -- https://master.php.net/note/reject/114654
Search -- https://master.php.net/manage/user-notes.php