note 104807 deleted from function.array-replace by danbrown

From: Date: Fri, 08 Jul 2011 15:09:15 +0000
Subject: note 104807 deleted from function.array-replace by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-181354@lists.php.net to get a copy of this message
Note Submitter: ff7cayn at gmx dot de ---- @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; } } ?>

« previous php.notes (#181354) next »