开发者社区> 问答> 正文

PHP多维数组求和

Array ( [图书楼] => Array ( [0] => Array ( [serial_number] => 51907180020053 [power] => 111.92 )

        [1] => Array
            (
                [serial_number] => 11908061080007
                [power] => 152.24
            )

        [2] => Array
            (
                [serial_number] => 51907180020042
                [power] => 
            )

        [3] => Array
            (
                [serial_number] => 51907180020053
                [power] => 111.92
            )

        [4] => Array
            (
                [serial_number] => 51907180020079
                [power] => 8.91
            )

        [5] => Array
            (
                [serial_number] => 51907180020097
                [power] => 
            )

    )
[女生宿舍] => Array
    (
        [0] => Array
            (
                [serial_number] => 51907180020046
                [power] => 0.01
            )

    )
[男生宿舍] => Array
    (
        [0] => Array
            (
                [serial_number] => 51907180020061
                [power] => 
            )

    )
[东侧家属院一单元] => Array
    (
        [0] => Array
            (
                [serial_number] => 11908061080017
                [power] => 177.21
            )

    )
[东侧家属院二单元] => Array
    (
        [0] => Array
            (
                [serial_number] => 11908061080015
                [power] => 111.04
            )

    )
[东侧家属院三单元] => Array
    (
        [0] => Array
            (
                [serial_number] => 11908061080018
                [power] => 86.53
            )

    )
[西侧家属院一单元] => Array
    (
        [0] => Array
            (
                [serial_number] => 11908061080005
                [power] => 121.20
            )

    )
[西侧家属院二单元] => Array
    (
        [0] => Array
            (
                [serial_number] => 11908061080011
                [power] => 138.85
            )

    )
[西侧家属院三单元] => Array
    (
        [0] => Array
            (
                [serial_number] => 11908061080014
                [power] => 59.27
            )

    )
[家属院一单元] => Array
    (
        [0] => Array
            (
                [serial_number] => 11908061080010
                [power] => 105.90
            )

    )
[家属院二单元] => Array
    (
    )
[家属院三单元] => Array
    (
        [0] => Array
            (
                [serial_number] => 11908061080002
                [power] => 104.10
            )
    )
[家属院] => Array
    (
        [0] => Array
            (
                [serial_number] => 11908061080006
                [power] => 96.64
            )

    )
[餐厅] => Array
    (
        [0] => Array
            (
                [serial_number] => 51907180020067
                [power] => 
            )

        [1] => Array
            (
                [serial_number] => 51907180020076
                [power] => 
            )
    )

)、

我想得到图书楼,女生宿舍,每个健名下面的power的总和,然后让健名比如图书楼后的值直接是总和,小弟不才,这个循环不知道该咋写,求大佬指教

展开
收起
问问小秘 2020-01-09 17:18:12 430 0
1 条回答
写回答
取消 提交回答
  • 使用 var_export 或者 json_encode 后的数据再来,你这样没法测,不过简单的看起来,可以用 array_map+array_sum+array_column 解决 4115007588-5e158e81b225b_articlex.png

    2020-01-09 17:21:54
    赞同 展开评论 打赏
问答分类:
PHP
问答标签:
问答地址:
问答排行榜
最热
最新

相关电子书

更多
阿里云栖开发者沙龙PHP技术专场-深入浅出网络编程与swoole内核-吴镇宇 立即下载
PHP安全开发:从白帽角度做安全 立即下载
PHP 2017.北京 全球开发者大会——高可用的PHP 立即下载