Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use in_array function in Blade template in Laravel 4?

How can we use in_array function in a Blade template, in Laravel 4?

like image 281
Vikas Burman Avatar asked Jul 22 '14 09:07

Vikas Burman


1 Answers

You can use the in_array function normally as you'd do in a normal php file without the use of blade templating language. In your view something.blade.php, you can do something like:

<?php
    if (in_array($something, $an_array)) {
        echo "Yes";
    }
?>

If you want to in_array function inside an if statement, you can use the blade templating syntax for if statement, like following:

 @if (in_array($something, $an_array))
      <span>Something</span>
 @endif

But I highly recommend you not to call the in_array function or any other php functions inside the view file. Instead you can call the in_array function in the controller and only pass the variable containing the result to the view to display.

like image 185
SUB0DH Avatar answered Mar 24 '23 03:03

SUB0DH