samedi 26 janvier 2019

Looping a Multi Dimensional Array

I encountered this kind of array in my tasks. It's a multi dimensional array. In the form, I have this,

particular[particular][]
particular[percentage][]
particular[remarks][]

So what I'm doing is, I'm getting request

$inputs = $request->all();

this returns

 array:3 [▼
    "particular" => array:3 [▶]
    "percentage" => array:3 [▶]
    "remarks" => array:3 [▶]
 ]

inside, each of them have

 array:3 [▼
     "particular" => array:3 [▼
         0 => "11"
         1 => "22"
         2 => "33"
     ] 
     "percentage" => array:3 [▼
         0 => "11"
         1 => "22"
         2 => "33"
     ]
     "remarks" => array:3 [▼
         0 => "na1"
         1 => "na2"
         2 => "na3"
      ]
 ]

I tried looping it

foreach ($inputs as $input) {
     dd($input);
}

but I only get the first one "particular" => array:3 [▶]

What I'm after is, I need to save those value in database

 $particular = new Particular;
 $particular->particular = particular;
 $particular->percentage = percentage;
 $particular->remarks = remarks;
 $particular->save();



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire