久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

子數組中所有元素的總和 - PHP

Summing of all elements in the sub array - PHP(子數組中所有元素的總和 - PHP)
本文介紹了子數組中所有元素的總和 - PHP的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

我有以下數組作為 $main_array .想要對子數組中的所有元素求和,例如 [0]=>6, [1]=>11, [2]=>15.

I've got the following array as $main_array .Wanted to sum up all the elements in the sub array such as [0]=>6, [1]=>11, [2]=>15.

Array 
( 
[0] => Array 
       ( 
         [0] => 1 
         [1] => 2 
         [2] => 3 
       ) 
[1] => Array 
       ( 
         [0] => 2 
         [1] => 4 
         [2] => 5 
       ) 
[2] => Array 
       ( 
         [0] => 8 
         [1] => 4 
         [2] => 3 
         ) 
)

嘗試了以下代碼.

foreach ($main_array as $key => $value)
  $main_array[$key] = Array('1'=>array_sum($value));
print_r($main_array);

但是我得到的數組結構是,

But the array structure I got was,

Array 
( 
    [0] => Array 
    ( 
        [1] => 6 
    ) 
    [1] => Array 
    ( 
        [1] => 11
    ) 
    [2] => Array 
    ( 
        [1] => 15 
    ) 
)

我期待數組結構如下.

Array 
( 
    [0] => 6

    [1] => 11

    [2] => 15

)

提前致謝!

推薦答案

當你調用 Array 函數時,你明確地創建了一個數組,所以你必須從 Array('1'=>array_sum($value));

When you're calling Array function you're explicitly making an array so you have to remove this from Array('1'=>array_sum($value));

這就是你的代碼應該是什么樣子

This is how your code should look like

foreach ($main_array as $key => $value)
  $main_array[$key] = array_sum($value);

這篇關于子數組中所有元素的總和 - PHP的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

Joining 2 tables in SELECT(MYSQL/PHP)(在 SELECT(MYSQL/PHP) 中加入 2 個表)
How to make lt;option selected=quot;selectedquot;gt; set by MySQL and PHP?(如何使lt;option selected=“selectedgt;由 MySQL 和 PHP 設置?)
Auto populate a select box using an array in PHP(使用 PHP 中的數組自動填充選擇框)
PHP SQL SELECT where like search item with multiple words(PHP SQL SELECT where like search item with multiple words)
json_encode produce JSON_ERROR_UTF8 from MSSQL-SELECT(json_encode 從 MSSQL-SELECT 產生 JSON_ERROR_UTF8)
MySQL ORDER BY rand(), name ASC(MySQL ORDER BY rand(),名稱 ASC)
主站蜘蛛池模板: 日韩精品免费一区二区在线观看 | 欧美色综合 | 亚洲美女视频 | 69精品久久久久久 | 国产高清精品一区二区三区 | 欧美综合一区 | av网站在线看 | 欧美色图综合网 | 国产在线观看 | 成人亚洲一区 | 国产精品一区二区在线播放 | 在线国产一区二区 | 美女黄网 | 五月婷婷激情 | 91久久久久久久久久久 | 日韩高清中文字幕 | 亚洲91精品 | 色视频免费 | 99精品国产一区二区三区 | 欧美午夜一区二区三区免费大片 | 国产成人精品久久二区二区 | 欧美韩一区二区三区 | 亚洲国产日韩欧美 | 国产男女猛烈无遮掩视频免费网站 | 国产精品一区二区在线观看 | 国产区在线 | a级性视频| 二区av| 欧美一区二区三区视频在线播放 | 国产午夜精品视频 | 欧美久久影院 | 一区二区在线不卡 | 国产亚洲一区二区三区在线 | 国产免费一区二区三区网站免费 | 一区二区欧美在线 | 午夜日韩精品 | 欧美精品成人 | 91av在线电影 | 精精国产xxxx视频在线播放 | 91精品久久久久 | 最新中文字幕在线播放 |