RE: [PHP] array_push in array maps

From: Date: Wed, 03 May 2006 13:41:10 +0000
Subject: RE: [PHP] array_push in array maps
Groups: php.general 
Request: Send a blank email to php-general+get-235366@lists.php.net to get a copy of this message
[snip] Need solve another case regarding array maps. Is it possible to insert more values like with array_push in arrays as bellow? $colors = array( 'red' => '#ff0000', 'green' => 'X00ff00', 'blue' => '#0000ff' ); [/snip] // Append associative array elements function array_push_associative(&$arr) { $args = func_get_args(); array_unshift($args); // remove &$arr argument foreach ($args as $arg) { if (is_array($arg)) { foreach ($arg as $key => $value) { $arr[$key] = $value; $ret++; } } } return $ret; } $theArray = array(); echo array_push_associative($theArray, $items, $moreitems) . ' items added to $theArray.';

« previous php.general (#235366) next »