note 17818 deleted from function.array-reduce by jimw
| From: | jimw@php.net | Date: | Wed, 02 Jan 2002 01:46:46 +0000 |
| Subject: | note 17818 deleted from function.array-reduce by jimw | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-24107@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');