select check boxes

PHOTO EMBED

Sun Jul 09 2023 02:43:12 GMT+0000 (Coordinated Universal Time)

Saved by @Joe_Devs #php

<?php
$result = null;
if(isset($_POST['submit'])) {

   $foods = $_POST['foods'];

   foreach ($foods as $food){
       echo "You like {$food} <br>";
   }
}

?>



<form action="index.php" method="post">
    <input type="checkbox" name="foods[]" value="pizza"> pizza <br>
    <input type="checkbox" name="foods[]" value="hamburger">Hamburger <br>
    <input type="checkbox" name="foods[]" value="hotdog"> hotdog <br>
    <input type="checkbox" name="foods[]" value="taco"> taco <br>

    <input type="submit" value="Submit" name="submit">
</form>
content_copyCOPY

to interact with checkboxes make sure they have the same name value and to be able to use them in an array put brackets at the end of the name

https://www.youtube.com/watch?v=zZ6vybT1HQs