What is the potential issue with saving data in PHP arrays when submitting a form multiple times?

The potential issue with saving data in PHP arrays when submitting a form multiple times is that the data from previous form submissions may accumulate and cause memory consumption to increase. To solve this issue, you can clear the array before adding new form data to it each time the form is submitted.

<?php

// Initialize an empty array to store form data
$form_data = [];

// Check if the form has been submitted
if ($_SERVER["REQUEST_METHOD"] == "POST") {
    // Clear the array before adding new form data
    $form_data = [];

    // Add new form data to the array
    $form_data['name'] = $_POST['name'];
    $form_data['email'] = $_POST['email'];

    // Process the form data or perform other actions
}

?>