php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #12028 array_sum changed
Submitted: 2001-07-10 18:51 UTC Modified: 2003-06-05 09:29 UTC
Votes:1
Avg. Score:2.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:0 (0.0%)
Same OS:0 (0.0%)
From: lee at mediawaveonline dot com Assigned:
Status: Wont fix Package: Feature/Change Request
PHP Version: 4.0.6 OS: openbsd/linux
Private report: No CVE-ID: None
Have you experienced this issue?
Rate the importance of this bug to you:

 [2001-07-10 18:51 UTC] lee at mediawaveonline dot com
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

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2003-06-05 09:29 UTC] derick@php.net
This can be done in user space just fine. No need to add more specific function into PHP for this.

regards,
Derick
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Mar 19 11:01:28 2024 UTC