note 85375 added to function.array-sum

From: Date: Wed, 27 Aug 2008 18:29:48 +0000
Subject: note 85375 added to function.array-sum
Groups: php.notes 
Request: Send a blank email to php-notes+get-143893@lists.php.net to get a copy of this message
To elaborate on djyb2003 at yahoo dot fr. His function can be converted to recursive, but i've made a smaller function to do so: <?php function array_sum_all($array) { $func = create_function("&\$arr=0,\$key=0","static \$a=0; if(is_int(\$arr)) { \$a+=\$arr; } return \$a;"); array_walk_recursive($array,$func); return $func(); } $tab = array( 0 => array ("val1" => 2,"val2" => 5), 1 => array ("val1" => 6,"val2" => 10), "toto" => array ("val1" => 15,"val2" => 50) ); var_dump(array_sum_all($tab)); //This will output: int(88); ?> hope this helps someone ---- Server IP: 208.69.120.35 Probable Submitter: 76.79.232.25 ---- Manual Page -- http://www.php.net/manual/en/function.array-sum.php Edit -- https://master.php.net/note/edit/85375 Del: integrated -- https://master.php.net/note/delete/85375/integrated Del: useless -- https://master.php.net/note/delete/85375/useless Del: bad code -- https://master.php.net/note/delete/85375/bad+code Del: spam -- https://master.php.net/note/delete/85375/spam Del: non-english -- https://master.php.net/note/delete/85375/non-english Del: in docs -- https://master.php.net/note/delete/85375/in+docs Del: other reasons-- https://master.php.net/note/delete/85375 Reject -- https://master.php.net/note/reject/85375 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#143893) next »