PHP create get and set dynamic multiple checkbox value

Today we will see how to get the value of multiple checkbox values. If you want, you can save it in the database. Follow the code below. You can easily get the value of multiple checkbox values.

First of all, we have to create some files if you want to save them in the database and if you do not want to do it with an index file. You need to make a few checkboxes inside the Intex. If you want, you can make 2 to 3 checkboxes. You have to keep the name of each checkbox equal. For example, the value[] box followed by the third becket indicates that it is an array. If you want to know what array works, for now, click read more. Checkboxes are placed inside a form tag. If you want to know what the form tag works for, click read more now.

 PHP code

<?php 
    $educationArr=array('10th','12th','BSc','B.Tech','M.Tech');
    $arr=array(); 
        if(isset($_POST['submit'])){ 
        $arr=$_POST['education'];
        echo implode(", ",$arr); 
        echo "<br/><br/>";
        } 
?>

 HTML code 

<form method="post"> 
<?php foreach($educationArr as $list){?>
     <?php if(in_array($list,$arr)){?>
        <?php echo $list?>
        <input checked="checked" type="checkbox" name="education[]" value=" <?php echo $list?>"/> <br/> 
        <?php }else{ ?>
        <?php echo $list ?>
        <input type="checkbox" name="education[]" value="<?php echo $list?>"/>
        <br/> <?php } ?>
    <?php } ?> <br/><br/> 
        <input type="submit" name="submit"/>
 </form>

After that, you have to put a submit button so that after sending your data through getting post we will now start PHP code. To read PHP you need to know PHP Basic. If you want to know PHP basics then click read more now. We can take or show the data through getting if we want, but if it is taken through post then the thing is very good for security. Also if you want the value of the checkbox to be selected then you don’t have to do anything but just put this code in the input. I hope you like the tests, so visit http://forums.beginnerwebdeveloper.com/ now and do a count.

<?php if(in_array($list,$arr)){?>
     <?php echo $list?>
    <input checked="checked" type="checkbox" name="education[]" value=" <?php echo $list?>"/> <br/>
<?php } ?>

2 thoughts on “PHP create get and set dynamic multiple checkbox value”

Leave a Comment