2011-11-21 40 views
0

本人曾經多維數組這些值:array_sum()預計參數1是數組,雙給出

array 
    0 => 
    array 
     0 => float 0.11521247274056 
     1 => float 0.081839214900844 
     2 => float 0.084168850912272 
     3 => float 0.18520831868443 
    1 => 
    array 
     0 => float 0.92169978192452 
     1 => float 0.65471371920675 
     2 => float 0.84168850912272 
     3 => float 0.43215274359699 
    2 => 
    array 
     0 => float 0.23042494548113 
     1 => float 0.13094274384135 
     2 => float 0.16833770182454 
     3 => float 0.18520831868443 
    3 => 
    array 
     0 => float 0.038404157580188 
     1 => float 0.09353053131525 
     2 => float 0.056112567274848 
     3 => float 0.061736106228142 

現在,我想是每個組的總和。類似:

[0] [0] + [0] [1] + [0] [2] + [0] [3]

有了這個代碼,我得到這個錯誤:array_sum()預計參數1是數組,雙定

for ($i = 0; $i < $numCol; $i++) { 
    for ($j = 0; $j < $numCol; $j++) { 
     $sumResult[] = array_sum($result[$i][$j]); 
    } 
} 
+1

錯誤說你需要做的... – PeeHaa

回答

2

你需要一個數組來傳遞到array_sum但你逝去的每個值作了明確規定。試試這個:

for ($i = 0; $i < $numCol; $i++) { 
    $sumResult[] = array_sum($result[$i]);   
} 
+0

感謝什麼,這是更簡單,我想:) – user947462

相關問題