lundi 22 juin 2020

How to get key of dynamic created input fields in PHP

i have multiple input elements like:

<input type="text" name="attribute_name[attr_1]" placeholder="Attribute Name" class="form-control" required="">
<input type="text" name="attribute_name[attr_2]" placeholder="Attribute Name" class="form-control" required="">
..
..

Now i want to loop through all the input elements and i want to get array key also, i.e. attr_1 in this case :

i'm using the following code but it is not getting key:

foreach($request->input('attribute_name.*') as $key => $val)
               {
                   print_r($key);
                   print_r($val);
               }


via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire