Php 空数组don';t在Laravel刀片中显示为空
现在我试图检查视图何时接收到空数组Php 空数组don';t在Laravel刀片中显示为空,php,laravel,Php,Laravel,现在我试图检查视图何时接收到空数组 @if(! empty($array)) // Section content goes here... @foreach($array as $value) // All table data goes here... @endforeach @endif 当$array为空并导致异常时,上面的代码似乎仍在运行 当我尝试使用{{dd($array)}}转储数组时,我得到$array=[]听起来您可能有一个集合。您
@if(! empty($array))
// Section content goes here...
@foreach($array as $value)
// All table data goes here...
@endforeach
@endif
当$array
为空并导致异常时,上面的代码似乎仍在运行
当我尝试使用
{{dd($array)}}
转储数组时,我得到$array=[]
听起来您可能有一个集合。您只需执行count($array)
即可检查数组中记录的数量。它看起来像这样:
@if(count($array))
// Section content goes here...
@foreach($array as $value)
// All table data goes here...
@endforeach
@endif
现在应该隐藏该部分。如果只希望在数组中没有任何内容时跳过foreach,可以执行以下操作:
// Section content goes here...
@forelse($array as $value)
// All table data goes here...
@empty
// Optional message if it's empty
@endforelse
它将输出节内容并检查数组前面是否有任何值
您可以在中阅读有关刀片文件中循环的更多信息。您的阵列可能是一个循环吗 尝试使用,这将检查数组或集合是否为空,并显示另一个块。例如:
@forelse($array as $value)
{{ $value }}
@empty
array is empty
@endforelse
谢谢,但是当没有内容时,我需要隐藏整个部分。