我需要检查数据数组是否有特定的密钥,我试过这样:
@if ( ! empty($data['currentOffset']) )
<p>Current Offset: {{ $currentOffset }} </p>
@else
<p>The key `currentOffset` is not in the data array</p>
@endif
但我总是得到<p>The key
currentOffsetis not in the data array</p>
。
你可以使用@isset
:
@isset($data['currentOffset'])
{{-- currentOffset exists --}}
@endisset
使用以下:
@if (array_key_exists('currentOffset', $data))
<p>Current Offset: {{ $data['currentOffset'] }} </p>
@else
<p>The key `currentOffset` is not in the data array</p>
@endif
我想你需要这样的东西:
@if ( isset($data[$currentOffset]) )
...