2016-03-15 55 views
5

我有以下代码:循环通过嵌套阵列中Laravel刀片模板

@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 

当执行代码这是返回我一个错误

[ErrorException] 
Undefined index: date 

。其实我在another_index有价值,我可以打印它。

在此先感谢您的帮助。

[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% 
       ) 
+2

你应该张贴您的'DD($数据[“日常”])'这里的样品或某事喜欢这个。 –

+0

dd($ data ['another_index'])以及$ date索引的存在可以被验证。 – btl

+1

已添加another_index数据。我不知道为什么它告诉'日期'索引没有找到,就好像它没有接受变量值。 –

回答

0

看你的样品阵列这应该给你你想要才达到什么:

@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 
+0

这不是我想要的数据。我在$ data ['daily']和$ data ['another_index']中有数据,因为$ data是一个多维数组。 –

+0

你可以发布你的多维数组吗? –