dpspn60064 2017-11-04 08:58
浏览 93

如何从多维数组中提取数据

I have the following code how can i extract [real] value if [name] => Y Downtime Switch

[inputs] => Array
        (
            [1] => Array
                (
                    [name] => X Downtime Switch
                    [raw] => 10
                    [real] => 0.01
                    [unit] => V
                    [count] => 0
                    [maxval] => 10
                    [minval] => 0
                    [decimals] => 2
                    [alarm] => A---
                )

            [2] => Array
                (
                    [name] => Y Downtime Switch
                    [raw] => 9197
                    [real] => 9.2
                    [unit] => V
                    [count] => 0
                    [maxval] => 10
                    [minval] => 0
                    [decimals] => 2
                    [alarm] => ----
                )

            [3] => Array
                (
                    [name] => Z Run PR
                    [raw] => 9187
                    [real] => 9187
                    [unit] => mV
                    [count] => 0
                    [maxval] => 10000
                    [minval] => 0
                    [decimals] => 0
                    [alarm] => ----
                    )
)
  • 写回答

1条回答 默认 最新

  • dqxyh48864 2017-11-04 09:05
    关注

    For the sake of helping itself:

    <?php
    $data = [
        [
            'name' => "X Downtime Switch",
            'real' => 0.01,
        ],
        [
            'name' => "Y Downtime Switch",
            'real' => 9.2
        ],
        [
            'name' => "Z Run PR",
            'real' => 9187
        ]
    ];
    $output = null;
    array_walk($data, function($entry) use (&$output) {
        if ($entry['name'] == "Y Downtime Switch") {
            $output = $entry['real'];
        }
    } );
    var_dump($output);
    

    The output obviously is:

    float(9.2)
    

    However I really recommend to you to read a bit about how this place works:

    We are not here to do your work for you. We are here to help you with specific issues you run into while trying to solve your tasks yourself. That means you are expected to write your own code.

    评论

报告相同问题?

悬赏问题

  • ¥15 AT89C51控制8位八段数码管显示时钟。
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口