|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2003-06-05 09:29 UTC] derick@php.net
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sat Oct 25 22:00:01 2025 UTC |
I would like array_sum() to be able to handel multi-dimentional arrays. this doesnt work. <?php $test[][] = 1; $test[][] = 2; $test[][] = 3; echo array_sum($test); ?> ive wrote a simple function to make this work. <?php function array_sum_multi($value, $reset = '1') { static $sum; if ($reset) $sum = 0; if (is_array($value)) foreach($value as $pos => $val) array_sum_multi($val, 0); else $sum += $value; return $sum; } $test[][] = 1; $test[][] = 2; $test[][] = 3; echo array_sum_multi($test); ?> just would be nice to see included. Chris Lee lee@mediawaveonline.com