note 112282 deleted from function.array-replace by danbrown
| From: | danbrown@php.net | Date: | Wed, 05 Jun 2013 17:44:47 +0000 |
| Subject: | note 112282 deleted from function.array-replace by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-195068@lists.php.net to get a copy of this message | ||
Note Submitter: rafita.diaz
----
A little enhancement to w_barath at hotmail dot com function below that preserve keys order:
<?php
if (function_exists('array_replace') == false) {
/**
* Replace array_replace for PHP < 5.3
*
* @return array
*/
function array_replace()
{
$array = array();
$n = func_num_args();
$keys = array_keys(func_get_arg(0));
while ($n-- >0) {
$array += func_get_arg($n);
}
$rval = array();
foreach ($keys as $key) {
$rval[$key] = $array[$key];
}
return $rval;
}
}
?>