How can inputs be named in PHP to create an array for easy retrieval using $_POST?

To create an array of inputs in PHP for easy retrieval using $_POST, you can name the inputs using square brackets in the HTML form. This way, when the form is submitted, PHP automatically creates an array with the input names as keys and their values as values in the $_POST superglobal array. This makes it easy to loop through the array and retrieve the values of the inputs.

<form method="post">
  <input type="text" name="input[]" />
  <input type="text" name="input[]" />
  <input type="text" name="input[]" />
  <input type="submit" value="Submit" />
</form>

<?php
if ($_SERVER["REQUEST_METHOD"] == "POST") {
  $inputs = $_POST['input'];
  foreach($inputs as $input) {
    echo $input . "<br>";
  }
}
?>