What are the best practices for using arrays in PHP to handle multiple input fields for color changes?

When handling multiple input fields for color changes in PHP, it is best to use arrays to store the values. This allows for easier manipulation and iteration over the data. By naming the input fields with square brackets in the HTML form, PHP can automatically create an array with the input values. This makes it simple to loop through the array and apply the color changes accordingly.

<?php
if ($_SERVER["REQUEST_METHOD"] == "POST") {
    $colors = $_POST['colors'];
    
    foreach ($colors as $color) {
        // Apply color changes here
        echo "<div style='color: $color;'>Text with color $color</div>";
    }
}
?>

<form method="post">
    <input type="text" name="colors[]" placeholder="Enter color 1">
    <input type="text" name="colors[]" placeholder="Enter color 2">
    <input type="text" name="colors[]" placeholder="Enter color 3">
    <button type="submit">Submit</button>
</form>