Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:36916 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 91271 invoked from network); 10 Apr 2008 12:02:06 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 10 Apr 2008 12:02:06 -0000 Authentication-Results: pb1.pair.com header.from=helly@php.net; sender-id=unknown Authentication-Results: pb1.pair.com smtp.mail=helly@php.net; spf=unknown; sender-id=unknown Received-SPF: unknown (pb1.pair.com: domain php.net does not designate 85.214.94.56 as permitted sender) X-PHP-List-Original-Sender: helly@php.net X-Host-Fingerprint: 85.214.94.56 aixcept.net Linux 2.6 Received: from [85.214.94.56] ([85.214.94.56:53903] helo=h1149922.serverkompetenz.net) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id BE/8A-32943-BB10EF74 for ; Thu, 10 Apr 2008 08:02:06 -0400 Received: from dhcp-172-28-202-217.zrh.corp.google.com (unknown [193.142.125.1]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by h1149922.serverkompetenz.net (Postfix) with ESMTP id B8DA311DC81; Thu, 10 Apr 2008 14:02:00 +0200 (CEST) Date: Thu, 10 Apr 2008 14:02:01 +0200 Reply-To: Marcus Boerger X-Priority: 3 (Normal) Message-ID: <603701944.20080410140201@marcus-boerger.de> To: Christian Schneider CC: PHP Developers Mailing List In-Reply-To: <8A963872-3893-4944-A5BF-C227421C095B@cschneid.com> References: <8A963872-3893-4944-A5BF-C227421C095B@cschneid.com> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-15 Content-Transfer-Encoding: 8bit Subject: Re: [PHP-DEV] [PATCH] Allow mixed $initial in array_reduce From: helly@php.net (Marcus Boerger) Hello Christian, looks good to me. Sidenote: If you cvs add the new test and then do cvs di -N, then you get the new files and the stuff you changed in one diff. If you do not have access then a) you need to do the cvs add step manually by editing the CVS/Entries file and putting in a dummy line for each new file. And b) you need to find someone to commit this patch to head first then 5.3. marcus Tuesday, April 8, 2008, 3:17:32 AM, you wrote: > --TEST-- > Test array_reduce() function > --INI-- > precision=14 > --FILE-- > /* Prototype: array array_reduce(array $array, mixed $callback, mixed $initial); > Description: Iteratively reduce the array to a single value via the callback > */ > $array = array('foo', 'foo', 'bar', 'qux', 'qux', 'quux'); > echo "\n*** Testing array_reduce() to integer ***\n"; > function reduce_int($w, $v) { return $w + strlen($v); } > $initial = 42; > var_dump(array_reduce($array, 'reduce_int', $initial), $initial); > echo "\n*** Testing array_reduce() to float ***\n"; > function reduce_float($w, $v) { return $w + strlen($v) / 10; } > $initial = 4.2; > var_dump(array_reduce($array, 'reduce_float', $initial), $initial); > echo "\n*** Testing array_reduce() to string ***\n"; > function reduce_string($w, $v) { return $w . $v; } > $initial = 'quux'; > var_dump(array_reduce($array, 'reduce_string', $initial), $initial); > echo "\n*** Testing array_reduce() to array ***\n"; > function reduce_array($w, $v) { $w[$v]++; return $w; } > $initial = array('foo' => 42, 'bar' => 17, 'qux' => -2, 'quux' => 0); > var_dump(array_reduce($array, 'reduce_array', $initial), $initial); > echo "\nDone"; ?>> > --EXPECTF-- > *** Testing array_reduce() to integer *** > int(61) > int(42) > *** Testing array_reduce() to float *** > float(6.1) > float(4.2) > *** Testing array_reduce() to string *** > string(23) "quuxfoofoobarquxquxquux" > string(4) "quux" > *** Testing array_reduce() to array *** > array(4) { > ["foo"]=> > int(44) > ["bar"]=> > int(18) > ["qux"]=> > int(0) > ["quux"]=> > int(1) > } > array(4) { > ["foo"]=> > int(42) > ["bar"]=> > int(17) > ["qux"]=> > int(-2) > ["quux"]=> > int(0) > } > Done Best regards, Marcus