Reputation: 20232
I need to check if the data array has a specific key, I tried it like this:
@if ( ! empty($data['currentOffset']) )
<p>Current Offset: {{ $currentOffset }} </p>
@else
<p>The key `currentOffset` is not in the data array</p>
@endif
But I always get <p>The key
currentOffsetis not in the data array</p>
.
Upvotes: 11
Views: 26655
Reputation: 1696
ternary
@php ($currentOffset = isset($data['currentOffset']) ? $data['currentOffset'] : '')
Upvotes: 0
Reputation: 8351
I think you need something like this:
@if ( isset($data[$currentOffset]) )
...
Upvotes: 5
Reputation: 1354
Use following:
@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
Upvotes: 4
Reputation: 163768
You can use @isset
:
@isset($data['currentOffset'])
{{-- currentOffset exists --}}
@endisset
Upvotes: 28