Insert input value into array

0

How to store the values of an input in positions of an array? I would like to get the value that was typed in the field and store it in an array, where I need to sort the values that were added in the array and sort them in descending order.

Ex:

<?PHP
echo"<tr>
   <td>
     <input type="text" name="campos" value="">
   </td>
   <td>
      <input type="submit" value="Submit">
   </td>
</tr>";
?>
    
asked by anonymous 31.08.2016 / 18:22

1 answer

6

Just put the field name with keys at the end. nomedocampo[] . So assuming this is a form, when you send it with a post to the backend.

The backend will understand that this set of fields with the same name is an array and will transform it into a single object $_POST['nomedocampo']

<input type="text" name="campos[]" value="">

<input type="text" name="campos[]" value="">

<input type="text" name="campos[]" value="">


<input type="submit" value="Submit">
    
31.08.2016 / 19:43