如何在foreach的数组中访问数组?

如何在foreach的数组中访问数组?我试图在Drupal上使用PHP和Twig在表中呈现数据。

这是我当前的代码:

$list = [];

    foreach($retrieveAlarmConfiguration['configList'] as $key => $value){

       $filter = true;

        foreach($value as $keyCL => $valueCL){          
            switch($keyCL){
                case 'deviceId':
                    if(!empty ( $deviceId ) && !($deviceId == $valueCL)){
                            $filter = false;
                        }
                case 'deviceModel':
                    if(!empty ( $deviceModel ) && !($deviceModel == $valueCL)){
                            $filter = false;
                        }
            } 

            foreach($valueCL as $keyCL1 => $valueCL1){
                switch($keyCL1){
                    case 'ruleDesc':
                    if(!empty ( $ruleDesc ) && !($ruleDesc == $valueCL)){
                            $filter = false;
                        }
                    break;
                    case 'alarmStatus':
                        if(!empty ( $alarmStatus ) && !($alarmStatus == $valueCL)){
                                $filter = false;
                            }
                        break;
            }


        }


            }

            if($filter){
                $list[] = $retrieveAlarmConfiguration['configList'][$key]; 
            }

            }

            $retrieveAlarmConfiguration['configList'] = $list;


    $output[OUT_DATA] = [
        'retrieveAlarmConfiguration' => $retrieveAlarmConfiguration[configList],
        'end' => $end
    ];

    return render($output,true);

这是当前数组:

{
"configList": [{
    "deviceId": "device45",
    "deviceModel": "Model123",
    "deviceType": "CAN_DEV_DEVICE",
    "disabledRulesCount": 0,
    "rulesList": [{
        "alarmStatus": "expired",
        "disabledEndDate": "2020-01-28T15:06:19",
        "lastUpdateDate": "2020-02-04T19:17:59",
        "ruleDesc": "this is a test description",
        "ruleEventCategory": "ERR",
        "ruleEventCode": 854,
        "ruleEventType": "YBN",
        "ruleName": "CANON_RE_WRT_ERROR_ES_2_1",
        "srFlag": true,
        "userName": "beebe23"
    }, {
        "alarmStatus": "expired",
        "disabledEndDate": "2020-01-28T15:06:19",
        "lastUpdateDate": "2020-01-02T15:06:19",
        "ruleDesc": "this is a test description",
        "ruleEventCategory": "ERR",
        "ruleEventCode": 328,
        "ruleEventType": "GMM",
        "ruleName": "CANON_RE_WRT_ERROR_ES_2_1",
        "srFlag": true,
        "userName": "beebe23"
    }, {
        "alarmStatus": "enabled",
        "disabledEndDate": "2020-02-29T17:00:28",
        "lastUpdateDate": "2020-01-08T11:07:07",
        "ruleDesc": "Alarm wrt 01 edited",
        "ruleEventCategory": "ERR",
        "ruleEventCode": "9903_100",
        "ruleEventType": "PLC  ",
        "ruleName": "CANON_RE_WRT_9903_ERROR_ES_2_1",
        "srFlag": true,
        "userName": "beebe23"
    }]
}, {
    "deviceId": "noreg_1004",
    "deviceModel": "Intermac",
    "deviceType": "INTERMAC_DEVICE",
    "disabledRulesCount": 1,
    "rulesList": [{
        "alarmStatus": "disabled",
        "disabledEndDate": "2021-01-01T00:00:00",
        "lastUpdateDate": "2020-01-23T12:55:49",
        "note": "Test 1",
        "ruleDesc": "this is a test description",
        "ruleEventCategory": "PLC",
        "ruleEventCode": "134_300",
        "ruleEventType": "BBOX",
        "ruleName": "CANON_RE_SELCO_H_2_1",
        "userName": "beebe23"
    }, {
        "alarmStatus": "expired",
        "disabledEndDate": "2020-02-01T00:00:00",
        "lastUpdateDate": "2020-01-23T12:55:49",
        "note": "Test 2",
        "ruleDesc": "BBOX - 26_200 - Left round corner PR1.3 safety switch ",
        "ruleEventCategory": "PLC",
        "ruleEventCode": "26_200",
        "ruleEventType": "BBOX",
        "ruleName": "CANON_RE_EDGE_MEDIUM_2_1",
        "userName": "angela"
    }]
}]

这些表中显示的唯一数据是“ deviceId”,“ deviceModel”,“ deviceType”,“ disabledRulesCount”和“ ruleList [array]”。我似乎无法访问ruleList数组中的内容?

这是我的html树枝文件:

{% for key, val in data['retrieveAlarmConfiguration'] %}
    <div class="row word-style table-border highlightedRow">
    <div class="col-xs-1 break-word">  {{ val["deviceModel"] }}  - {{ val["deviceId"] }} </div>

    <div class="col-xs-1">{{ val["ruleDesc"] }} </div>

    </div>

{% endfor %}

知道我在做什么错吗?

评论