What are some alternative methods to handle checkbox inputs in PHP forms for better readability and efficiency?

When handling checkbox inputs in PHP forms, it can be challenging to manage multiple checkboxes and their corresponding values efficiently. One way to improve readability and efficiency is to use arrays for checkbox inputs. By grouping related checkboxes under a single array, you can easily loop through them and process their values.

<form method="post">
    <input type="checkbox" name="fruits[]" value="apple"> Apple
    <input type="checkbox" name="fruits[]" value="banana"> Banana
    <input type="checkbox" name="fruits[]" value="orange"> Orange
    <input type="submit" name="submit" value="Submit">
</form>

<?php
if(isset($_POST['submit'])) {
    if(isset($_POST['fruits'])) {
        foreach($_POST['fruits'] as $fruit) {
            echo $fruit . "<br>";
        }
    }
}
?>