1

I have a common array from request named complemntartData[]. from that array i get some values.i need to store these data in db table field.i used implode function but it shows array to string conversion. this is complementaryData


    if($request->input('complementaryData')){
       foreach($request->input('complementaryData') as $name => $value){
          $data = explode ("_", $name);
          $A = [];
          $B = [];
          if($data[0]=="TextField"){
            $B["id"] = $data[1];
            $A["TextField"] = &$B;
            $B["data"] = $value;
           }
           if($data[0]=="Archive"){
              $B["id"] = $data[1];
              $A["Archive"] = &$B;
              $B["data"] = $value;
           }
           if($data[0]=="MultipleChoice"){
              $B["id"] = $data[1];
              $A["MultipleChoice"] = &$B;
              $B["sub"] = $value;
           }
           $eventParticipants->complementaryData = implode(',',$A);
           //dd($eventParticipants->complementaryData);
        }
   }

Sindhu Diya
  • 79
  • 1
  • 7

1 Answers1

0
implode(',', $A['Archive']);

The error comes from you passing a multidimensional array to implode: implode-data-from-a-multi-dimensional-array

Also if you want to store array data in single field, I would rather use serialize: serialize($A) can be easily unpacked using the unserialize() function

Peter Szalay
  • 376
  • 3
  • 13