Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/231.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/laravel/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php empty()函数返回false,尽管数组包含空数组_Php_Laravel - Fatal编程技术网

Php empty()函数返回false,尽管数组包含空数组

Php empty()函数返回false,尽管数组包含空数组,php,laravel,Php,Laravel,我不知道为什么尽管没有任何数据匹配雪兰莪州,但显示“未找到记录”的所需行没有显示 集市管理员: public function index() { $bzr = BzrLocation::where('area', 'Perlis')->get(); $bzr2 = BzrLocation::where('area', 'Selangor')->get(); $bzr3 = BzrLocation::where('area',

我不知道为什么尽管没有任何数据匹配雪兰莪州,但显示“未找到记录”的所需行没有显示

集市管理员:

public function index()
    {
        $bzr = BzrLocation::where('area', 'Perlis')->get();
        $bzr2 = BzrLocation::where('area', 'Selangor')->get();
        $bzr3 = BzrLocation::where('area', 'Pahang')->get();
        $bzr4 = BzrLocation::where('area', 'Johor')->get();
        $bzr5 = BzrLocation::where('area', 'Melaka')->get();
        $bzr6 = BzrLocation::where('area', 'Negeri Sembilan')->get();

    $allbzr = [
        'bzrloc' => $bzr,
        'bzrloc2' => $bzr2,
        'bzrloc3' => $bzr3,
        'bzrloc4' => $bzr4,
        'bzrloc5' => $bzr5,
        'bzrloc6' => $bzr6
    ];

    return view('admin.bazaarloc')->with($allbzr);
   }
bazaarloc.blade.php:

<table class="table table-hover">
   <caption>Table 2</caption>
   <thead class="thead-dark">
     <tr>
       <th scope="col" style="width: 8%; vertical-align: top;">No.</th>
       <th scope="col" style="width: 60%; vertical-align: top;">Location</th>
       <th scope="col" style="width: 21%; vertical-align: top;">Amount Approved</th>
       <th scope="col" style="width: 21%; vertical-align: top;">Description</th>
       <th scope="col" style="width: 4%;"></th>
       <th scope="col" style="width: 4%;"></th>
     </tr>
   </thead>
   <tbody>
     @php
     $counting = 0
     @endphp
     @foreach($bzrloc2 as $bzr)
     @php
     $counting++
     @endphp
     <tr>
       <th scope="row">{{$counting}}</th>
       <td>{{$bzr->name}}</td>
       <td>{{$bzr->totalPlot}}</td>
       <td>{{$bzr->plotAvail}}</td>
       <td><a href="{{ route('bazaarLocation.edit', $bzr->bzrloc_id) }}"><button type="submit" class="btn btn-success btn-sm">Edit</button></a></td>
       <td>
         <form method="POST" action="{{ route('bazaarLocation.destroy', $bzr->bzrloc_id) }}">
             @csrf
             @method('DELETE')
             <button type="submit" class="btn btn-danger btn-sm" onclick="return confirm('Adakah anda pasti ingin membatalkan lokasi tersebut?')">Batal</button>
         </form>
       </td>
     </tr>
     @endforeach
     @if(empty($bzrloc2))
     <tr>
       <td colspan="2">
         No record found
       </td>
     </tr>
     @endif
   </tbody>
 </table>

表2
不
位置
核准金额
描述
@php
$counting=0
@endphp
@foreach($bzrloc2作为$bzr)
@php
美元计数++
@endphp
{{$counting}
{{$bzr->name}
{{$bzr->totalPlot}
{{$bzr->plotAvail}
@csrf
@方法('DELETE')
巴塔尔
@endforeach
@如果(空($bzrloc2))
没有找到任何记录
@恩迪夫

打印$bzrloc2时,显示[]。确认数组为空。基于PHP手册,EMPTY()函数应该考虑这个空和返回true。

< P>当您使用<代码> -GET()/代码>检索时,您应该使用<代码>计数()/代码>函数,以检查<强>集合< >强>是否为空。< /P> 请尝试使用计数,而不是使用空值,如:

@if($bzrloc2->count() < 1)
     <tr>
       <td colspan="2">
         No record found
       </td>
     </tr>
     @endif
@if($bzrloc2->count()<1)
没有找到任何记录
@恩迪夫

使用
->get()
检索时,应使用
count()
函数检查集合是否为空

请尝试使用计数,而不是使用空值,如:

@if($bzrloc2->count() < 1)
     <tr>
       <td colspan="2">
         No record found
       </td>
     </tr>
     @endif
@if($bzrloc2->count()<1)
没有找到任何记录
@恩迪夫

因为您使用的是集合,而不是数组。集合将返回
false

empty(collect([]))  // false
empty([])           // true
请尝试以下代码:


表2
不
位置
核准金额
描述
@如果($bzrloc2->count())
@php
$counting=0
@endphp
@foreach($bzrloc2作为$bzr)
@php
美元计数++
@endphp
{{$counting}
{{$bzr->name}
{{$bzr->totalPlot}
{{$bzr->plotAvail}
@csrf
@方法('DELETE')
巴塔尔
@endforeach
@否则
没有找到任何记录
@恩迪夫

因为您使用的是集合,而不是数组。集合将返回
false

empty(collect([]))  // false
empty([])           // true
请尝试以下代码:


表2
不
位置
核准金额
描述
@如果($bzrloc2->count())
@php
$counting=0
@endphp
@foreach($bzrloc2作为$bzr)
@php
美元计数++
@endphp
{{$counting}
{{$bzr->name}
{{$bzr->totalPlot}
{{$bzr->plotAvail}
@csrf
@方法('DELETE')
巴塔尔
@endforeach
@否则
没有找到任何记录
@恩迪夫

打印到$allbzr并检查数据是否来自数据库?您是否还缺少一些@php?@dagelf-nope,它的complete@PHPGeek问题已经解决:)打印到$allbzr并检查数据是否来自数据库?您是否缺少更多的@php?@dagelf不,它的complete@PHPGeek问题已经解决了:)