All TalkersCode Topics

Follow TalkersCode On Social Media - A Social Media Network for developers Join Now ➔

How To Show Multiple Checkbox Checked In PHP

Last Updated : Mar 11, 2024

How To Show Multiple Checkbox Checked In PHP

In this tutorial we will show you the solution of how to show multiple checkbox checked in PHP, here, multiple checkboxes checked means we have to get values of that selected checkbox with help of php.

So, let us start our tutorial by understanding the example below.

Step By Step Guide On How To Show Multiple Checkbox Checked In PHP :-

Now, to get the values of the multiple checked checkboxes in PHP is very easy.

There are many ways with help of which we can do this. Let us understand one from them with the help of example given below.

    if(!empty($_POST['colors'])) {
        foreach($_POST['colors'] as $value){
            echo "Chosen Colors are : ".$value.'<br/>';
<!DOCTYPE html>
   <title> how to show multiple checkboxes checked in PHP </title>
<form method="post" action="">
    <span> Which is your favorite colors, you can choose more than one also ?</span>
    <input type="checkbox" name='colors[]' value="red"> RED <br/>
    <input type="checkbox" name='colors[]' value="yellow"> Yellow <br/>
    <input type="checkbox" name='colors[]' value="blue"> Blue <br/>
    <input type="checkbox" name='colors[]' value="black"> Black <br/>
    <input type="submit" value="Submit" name="submit">
  1. As, here we see that we that in above example we show you an example in which HTML and PHP codes are used.
  2. Here, first of all, we create a basic structure of HTML, in which we use <!DOCTYPE html> which defines the type of document. And next one is our HTML tags. These tags are paired tags and all the data regarding HTML is written inside these tags.
  3. After we use our head tag which is again paired tag and contains the title and meta information of the webpage. The data written inside the head is not shown on the webpage.
  4. Now, next is our title tag which defines the title of the webpage. The tag which has its closing tag is known as a paired tag. So, this is again a paired tag.
  5. Now, next is the body which is the main tag of HTML. The data which we have written inside the body is shown on the webpage. Mostly all tags which are helpful to show data or information on the screen are written under the body tag.
  6. Now, as above we see we first create a form and after that inside form, we just use input having type checkbox. With help of this we create multiple checkboxes and a submit button.
  7. At next inside php codes we see that we use foreach loop to get the required means checked checkboxes values. And using echo we display values on screen.

Conclusion :-

At last, in conclusion, here we can say that with the help of this article we can understand how to show multiple checkboxes checked in php.

I hope this tutorial on how to show multiple checkbox checked in PHP helps you and the steps and method mentioned above are easy to follow and implement.

Author Image About Riya

A recent graduate with a Bachelor of Technology (B.Tech) in Computer Science from India. She is passionate about leveraging technology to solve real-world problems. With a strong foundation and experience in programming languages such as Python, Django, HTML, CSS, and JavaScript, java, php and have honed her skills through hands-on projects and coursework.

Follow Riya On Linkedin 🡪