note 104807 added to function.array-replace
| From: | ff7cayn at gmx dot de | Date: | Fri, 08 Jul 2011 09:03:42 +0000 |
| Subject: | note 104807 added to function.array-replace | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-181347@lists.php.net to get a copy of this message | ||
@dyer85 and tufan:
There is an error in your code since it cannot replace with one fielded arrays.
The for loop mised an equal sign '<='
Here is the fixed version:
<?php
if (!function_exists('array_replace'))
{
function array_replace( array &$array, array &$array1, $filterEmpty=false )
{
$args = func_get_args();
$count = func_num_args()-1;
for ($i = 0; $i <= $count; ++$i) {
if (is_array($args[$i])) {
foreach ($args[$i] as $key => $val) {
if ($filterEmpty && empty($val)) continue;
$array[$key] = $val;
}
}
else {
trigger_error(
__FUNCTION__ . '(): Argument #' . ($i+1) . ' is not an array',
E_USER_WARNING
);
return NULL;
}
}
return $array;
}
}
?>
----
Server IP: 85.214.154.209
Probable Submitter: 217.92.254.84
----
Manual Page -- http://www.php.net/manual/en/function.array-replace.php
Edit -- https://master.php.net/note/edit/104807
Del: integrated -- https://master.php.net/note/delete/104807/integrated
Del: useless -- https://master.php.net/note/delete/104807/useless
Del: bad code -- https://master.php.net/note/delete/104807/bad+code
Del: spam -- https://master.php.net/note/delete/104807/spam
Del: non-english -- https://master.php.net/note/delete/104807/non-english
Del: in docs -- https://master.php.net/note/delete/104807/in+docs
Del: other reasons-- https://master.php.net/note/delete/104807
Reject -- https://master.php.net/note/reject/104807
Search -- https://master.php.net/manage/user-notes.php