note 92534 added to function.array-product

From: Date: Tue, 28 Jul 2009 17:34:18 +0000
Subject: note 92534 added to function.array-product
Groups: php.notes 
Request: Send a blank email to php-notes+get-158833@lists.php.net to get a copy of this message
gmail @ algofoogle is right, so we can extend our own array_product() to flexibly accept the empty product value. Zero (0) is the default (to be compatible with PHP behavior), but you could change this to 1 for mathematical purposes or null for logical. <?php if (! function_exists('array_product')) { function array_product($array, $emptyProduct = 0) { if (is_array($array)) { return (0 == count($array) ? $emptyProduct : array_reduce($array, '_array_product', 1)); } else { trigger_error('Param #1 must be an array', E_USER_ERROR); return false; } } function _array_product($v,$w) { return $v * $w; } } ?> ---- Server IP: 64.71.164.2 Probable Submitter: 24.148.150.180 ---- Manual Page -- http://www.php.net/manual/en/function.array-product.php Edit -- https://master.php.net/note/edit/92534 Del: integrated -- https://master.php.net/note/delete/92534/integrated Del: useless -- https://master.php.net/note/delete/92534/useless Del: bad code -- https://master.php.net/note/delete/92534/bad+code Del: spam -- https://master.php.net/note/delete/92534/spam Del: non-english -- https://master.php.net/note/delete/92534/non-english Del: in docs -- https://master.php.net/note/delete/92534/in+docs Del: other reasons-- https://master.php.net/note/delete/92534 Reject -- https://master.php.net/note/reject/92534 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#158833) next »