Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I know the size of an array in Blade template?

I need something like this:

@if ($array.length > 0)     {{-- expr --}} @endif 

is this possible?

like image 783
Andy.Diaz Avatar asked Jul 18 '14 02:07

Andy.Diaz


People also ask

How can we find array size?

We can find the size of an array using the sizeof() operator as shown: // Finds size of arr[] and stores in 'size' int size = sizeof(arr)/sizeof(arr[0]);

How do you show an array in blade?

You can access the array in the laravel blade using ['key']. Here are some examples like {{ $user['name'] }} and {{ $users[0]['name'] }}.

What is array size?

Array size. The size of an array is the product of the lengths of all its dimensions. It represents the total number of elements currently contained in the array. For example, the following example declares a 2-dimensional array with four elements in each dimension.


1 Answers

It is possible with the count function, like so:

@if (count($array) > 0)     {{-- expr --}} @endif 
like image 109
Andy.Diaz Avatar answered Oct 16 '22 20:10

Andy.Diaz