To check if a value exists in een array, you should use in_array. http://php.net/manual/en/function.in-array.php
Jun 7, 2017
4
Level 2
Blade Check if variable is in Array
Hi All,
I am a little stuck with a blade template, I need to check if a variable is in an array, how would I do this? The array can vary in length. If the value is found in the array I need to output a string.
Thanks!
Level 9
Hi Toneee,
You can use regular php within your blade if statements, such as
If you are looking for a keyname
@if(array_key_exists('keyname', $array_to_search))
{{ $array_to_search['keyname'] }}
@endif
http://php.net/manual/en/function.array-key-exists.php
Or searching for a particular value
@if(in_array('value', $array_to_search))
Output String
@endif
http://php.net/manual/en/function.in-array.php
Neil
5 likes
Please or to participate in this conversation.