简体   繁体   English

在Laravel Blade模板中循环嵌套数组

[英]Looping through nested array in Laravel Blade template

I have the following code : 我有以下代码:

@foreach($data['daily'] as $date => $dailyData)
    <tr>
        <td>{{$date}}</td>
        @foreach($dailyData as $key => $value)
            <td>
                <span>{{$value}}</span>
                <strong>{{$data['another_index'][$date][$key]}}</strong>
            </td>
        @endforeach
    </tr>
@endforeach

This is returning me an error 这让我错了

[ErrorException]
Undefined index: date

When the code is executed. 代码执行时。 Actually I have values there in another_index and I am able to print it. 实际上我在another_index有值,我可以打印它。

Thanks in advance for the help. 先谢谢您的帮助。

[another_index] => Array
        (
            [2016-03-15] => Array
                (
                    [key] => 100.00%
                    [key1] => 0.00%
                    [key2] => 0.00%
                )

            [2016-03-14] => Array
                (
                    [key] => 10.00%
                    [key1] => 20.00%
                    [key2] => 30.00%
                )

Looking at your sample array this should give you what you're trying to achive: 看看你的示例数组,这应该会给你你想要实现的目标:

@foreach($data as $date => $dailyData)
    <tr>
        <td>{{$date}}</td>
        @foreach($dailyData as $key => $value)
            <td>
                <span>{{$key}}</span>
                <strong>{{$value}}</strong>
            </td>
        @endforeach
    </tr>
@endforeach

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM