How can we use in_array
function in a Blade template, in Laravel 4?
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With