简体   繁体   中英

Laravel Getting an error Undefined offset: 3

I am getting an error in my laravel application. The error states that Undefined offset:3.

Controller

        public function updateVisaDocuments($type, $details, $visa, $documents_id){
    $visas_documents_db = \App\VisaDocuments::where ( 'visa_id', $visa->id )->get();
    foreach($visas_documents_db as $document_db){
        $count=0;
        for($j = 0; $j < sizeof ( $documents_id ); $j ++) {
            if($document_db->id==$documents_id [$j]){
                $count++;
            }
        }
        if($count==0)
            $document_db->delete();
    }

    for($i = 0; $i < sizeof ( $type ); $i++) {
        if(!empty($type[$i])){
            if(!empty($documents_id[$i])){
                $visa_documents = \App\VisaDocuments::where ( 'id', $documents_id[$i] )->first ();
            }else{
                $visa_documents=new VisaDocuments();
                $visa_documents->id=Uuid::generate ();
            }
                $visa_documents->type=$type[$i];
                $visa_documents->details=json_encode($details);
                $visa_documents->visa_id=$visa->id;
                if(!empty($documents_id[$i]))
                    $visa_documents->update();
                else
                    $visa_documents->save();
        }
    }
}
 foreach ($visa->documents as $documents){
    $i++;
    $det=json_decode($documents->details,true);
    $size_det=sizeof($det);
    $size_det_inside=sizeof($det[$i]);
    $k=0;

View

<?php $size_det_inside = sizeof($det[$i]);?>
@for($j=0; $j< $size_det_inside; $j++)
@if($det[$i][$j] != '')
<input type="text" name="document_details[{{$i}}][]" value="{{$det[$i][$j]}}" />

@endif
@endfor 

I am getting error here sizeof($det[$i]); (View). I guess, the result is in json format and in my view file i am treating it as variable.

Can anyone please help me on this.

If your php version is 7.0 or above, you should use count() function instead of sizeof(). Please use count().

http://php.net/manual/en/function.sizeof.php

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM