note 17818 added to function.array-reduce

From: Date: Thu, 27 Dec 2001 01:21:11 +0000
Subject: note 17818 added to function.array-reduce
Groups: php.notes 
Request: Send a blank email to php-notes+get-23852@lists.php.net to get a copy of this message
Need to reduce a hash? This function will create a list of key/value pairs from a hash: function array_items($array) { $result = array(); foreach ($array as $key => $val) array_push($result, array($key, $val)); return $result; } Just set your reduction function up like this: function my_reduce($accum, $key_val) { list($key, $val) = $key_val; // ... } And call it like this: array_reduce(array_items($array), 'my_reduce'); -- http://www.php.net/manual/en/function.array-reduce.php http://master.php.net/manage/user-notes.php?action=edit+17818 http://master.php.net/manage/user-notes.php?action=delete+17818 http://master.php.net/manage/user-notes.php?action=reject+17818

« previous php.notes (#23852) next »