note 17833 deleted from function.array-sum by jimw

From: Date: Wed, 02 Jan 2002 11:13:04 +0000
Subject: note 17833 deleted from function.array-sum by jimw
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-24208@lists.php.net to get a copy of this message
A warning... I am using php 4.04pl1 and whenever I use the array sum function on an array containing both string and numeric values, it does the sum of the numeric values properly, but turns all non-number values in the array into the value "0" (zero). I tried creating a function that copied the array into another variable so that it would not be operating on the original... but mysteriously, it still destroyed the string values in the original array! Making a copy of the array into a new variable before passing it to the function seemed to work okay, but I didn't want to do that for my particular operation. My workaround was to create a function to use in place of sum_array. This is, of course, quick and dirty. function num_array_sum($the_array) { $num = count($the_array); $y=0; for ($i = 0; $i < $num; $i++) { $y = $y + $the_array[$i]; } return $y; }

« previous php.notes (#24208) next »