How can the values in an array be properly displayed in input fields after form submission in PHP?

When a form is submitted in PHP and the values from the form are stored in an array, those values can be displayed in input fields by using the "value" attribute in the input field tag. To do this, loop through the array and set the "value" attribute of each input field to the corresponding value from the array.

<?php
if ($_SERVER["REQUEST_METHOD"] == "POST") {
    $values = $_POST['values']; // Assuming 'values' is the name of the array in the form
    
    foreach ($values as $key => $value) {
        echo '<input type="text" name="values[]" value="' . $value . '"><br>';
    }
}
?>