php 计算二维数组中某一元素之和

array(2)(
    [0] => array(5) {
      ["id"] => string(2) "11"
      ["name"] => string(5) "1.jpg"
      ["suffix"] => string(3) "jpg"
      ["url"] => string(29) "./Uploads/1/5292f55d208e8.jpg"
      ["size"] => string(6) "715895"
    }
    [1] => array(5) {
      ["id"] => string(2) "12"
      ["name"] => string(22) "minisite数据库.docx"
      ["suffix"] => string(4) "docx"
      ["url"] => string(30) "./Uploads/1/5292f5606a52c.docx"
      ["size"] => string(5) "16667"
    }
)
//例子一
array(2) {
  [0] => array(1) {
    ["money"] => string(4) "0.27"
  }
  [1] => array(1) {
    ["money"] => string(4) "0.42"
  }
}
//例子二

计算size的和:

$sum = 0;
foreach($arr as $item){
  $sum += (int) $item['size'];
}

 例子一需要(int),例子二不需要

上一篇:python转换doc为docx


下一篇:JAVA 使用模板创建DOCX文档)(XDocService 使用报错条数过多报错链接不上服务器)