{"id":14419,"date":"2016-08-17T16:15:48","date_gmt":"2016-08-17T13:15:48","guid":{"rendered":"http:\/\/www.webcodegeeks.com\/?p=14419"},"modified":"2018-01-09T10:40:04","modified_gmt":"2018-01-09T08:40:04","slug":"php-checkbox-example","status":"publish","type":"post","link":"https:\/\/www.webcodegeeks.com\/php\/php-checkbox-example\/","title":{"rendered":"PHP Checkbox Example"},"content":{"rendered":"<p>Checkboxes are those HTML elements that behave like toggle switches. So, unlike the radio buttons, checkboxes do not enforce to select an option from a group of options; we can select as much as we want. In this example, we will see how to deal with these checkboxes in PHP.<\/p>\n<p>For this example, we will use:<\/p>\n<ul>\n<li>Linux Mint (17.03) as Operating System.<\/li>\n<li>Apache HTTP server (2.4.7).<\/li>\n<li>PHP (5.5.9).<\/li>\n<\/ul>\n<div class=\"tip\"><strong>Tip<\/strong><br \/>\nYou may skip environment preparation and jump directly to the <a href=\"#section_2\"><strong>beginning of the example<\/strong><\/a> below.<\/div>\n<p>&nbsp;<br \/>\n[ulp id=&#8217;8njY7i2QRy6sg8pg&#8217;]<\/p>\n<h2>1. Preparing the environment<\/h2>\n<p>Below, commands to install Apache and PHP are shown:<\/p>\n<pre class=\"brush:bash\">sudo apt-get update\r\nsudo apt-get install apache2 php5 libapache2-mod-php5\r\nsudo service apache2 restart<\/pre>\n<p><strong>Note:<\/strong> if you want to use Windows, installing XAMPP is the fastest and easiest way to install a complete web server that meets the prerequisites.<\/p>\n<h2 id=\"section_2\">2. HTML Form<\/h2>\n<p>Let&#8217;s see with a simple form how the checkboxes work:<\/p>\n<p><span style=\"text-decoration: underline;\"><em>form.html<\/em><\/span><\/p>\n<pre class=\"brush:html\">&lt;!DOCTYPE html&gt;\r\n&lt;head&gt;\r\n\u00a0\u00a0\u00a0 &lt;meta charset=\"UTF-8\"&gt;\r\n\u00a0\u00a0\u00a0 &lt;title&gt;HTML form&lt;\/title&gt;\r\n\u00a0\u00a0\u00a0 &lt;style&gt;\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 html {\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 width: 35%;\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 }\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 .form-input {\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 margin-bottom: 20px;\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 }\r\n\u00a0\u00a0\u00a0 &lt;\/style&gt;\r\n&lt;\/head&gt;\r\n&lt;body&gt;\r\n\u00a0\u00a0\u00a0 &lt;form method=\"GET\" action=\"process.php\"&gt;\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 &lt;div class=\"form-input\"&gt;\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 &lt;label for=\"name\"&gt;Your name&lt;\/label&gt;\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 &lt;input type=\"text\" name=\"name\" id=\"name\" required&gt;\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 &lt;\/div&gt;\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 &lt;div class=\"form-input\"&gt;\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 &lt;fieldset&gt;\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 &lt;legend&gt;Programming languages you have worked with&lt;\/legend&gt;\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 &lt;div&gt;\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 &lt;input type=\"checkbox\" name=\"programming-languages[]\" id=\"python\" value=\"Python\"&gt;\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 &lt;label for=\"python\"&gt;Python&lt;\/label&gt;\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 &lt;\/div&gt;\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 &lt;div&gt;\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 &lt;input type=\"checkbox\" name=\"programming-languages[]\" id=\"php\" value=\"PHP\" checked&gt;\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 &lt;label for=\"php\"&gt;PHP&lt;\/label&gt;\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 &lt;\/div&gt;\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 &lt;div&gt;\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 &lt;input type=\"checkbox\" name=\"programming-languages[]\" id=\"haskell\" value=\"Haskell\"&gt;\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 &lt;label for=\"haskell\"&gt;Haskell&lt;\/label&gt;\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 &lt;\/div&gt;\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 &lt;div&gt;\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 &lt;input type=\"checkbox\" name=\"programming-languages[]\" id=\"other\" value=\"Other\"&gt;\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 &lt;label for=\"other\"&gt;Other&lt;\/label&gt;\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 &lt;\/div&gt;\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 &lt;\/fieldset&gt;\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 &lt;\/div&gt;\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 &lt;div class=\"form-input\"&gt;\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 &lt;input type=\"submit\" value=\"Submit\"&gt;\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 &lt;\/div&gt;\r\n\u00a0\u00a0\u00a0 &lt;\/form&gt;\r\n&lt;\/body&gt;\r\n&lt;\/html&gt;<\/pre>\n<p>For which the following rendering will be generated:<\/p>\n<figure style=\"width: 471px\" class=\"wp-caption aligncenter\"><img decoding=\"async\" src=\"http:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2016\/08\/Form.jpg\" width=\"471\" height=\"290\" \/><figcaption class=\"wp-caption-text\">Example form with checkboxes.<\/figcaption><\/figure>\n<p>The are some things that we have to know:<\/p>\n<ul>\n<li>We can set the checkboxes checked from the beginning with the <code>checked<\/code> attribute (line 28). By default, the checkboxes are unchecked.<\/li>\n<li>Note that each checkbox name ends with <code>[]<\/code>. This is for accessing the selected values of the checkboxes with the same name as an array. If we leave the same name but with the square brackets in the end, PHP will only be able to retrieve the last item.<\/li>\n<li>HTML5 does not provide a standard way of marking a group of checkboxes as <code>required<\/code>. This can be achieved with JavaScript, but it&#8217;s not the aim of this example.<\/li>\n<\/ul>\n<h2>3. Form handling<\/h2>\n<p>The only difference in the form processing with other form elements is that PHP takes the elements of a checkbox group as an array, as previously mentioned.<\/p>\n<p>But the way the data is submitted is not different from other elements. This is an example of the data generated for our <code>GET<\/code> request:<\/p>\n<pre class=\"brush:bash\">process.php?name=Julen&amp;programming-languages[]=PHP&amp;programming-languages[]=Other<\/pre>\n<p>As you can see, there are two different values with the same name, which makes sense since we have chosen different values that share the name. But PHP will know that, when retrieving these values, it has to put them inside an array, because of the square brackets <code>[]<\/code> placed in the end of each parameter name.<\/p>\n<p>So, processing this form data would be pretty simple, as shown in the following script:<\/p>\n<p><span style=\"text-decoration: underline;\"><em>process.php<\/em><\/span><\/p>\n<pre class=\"brush:php;highlight:[27,28,29,46]\">&lt;?php\r\n\r\n\/**\r\n\u00a0* Checks if the given parameters are set. If one of the specified parameters\r\n\u00a0* is not set, die() is called.\r\n\u00a0*\r\n\u00a0* @param $parameters The parameters to check.\r\n\u00a0*\/\r\nfunction checkGETParametersOrDie($parameters) {\r\n\u00a0\u00a0\u00a0 foreach ($parameters as $parameter) {\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 isset($_GET[$parameter]) || die(\"'$parameter' parameter must be set.\");\r\n\u00a0\u00a0\u00a0 }\r\n}\r\n\r\n\/**\r\n\u00a0* Print the submitted data. If the value is an array, is imploded to a string.\r\n\u00a0*\r\n\u00a0* @param array $data The form data, with $name =&gt; $value format.\r\n\u00a0*\/\r\nfunction printData($data) {\r\n\u00a0\u00a0 \u00a0echo 'You have submitted the form with the following data:&lt;br&gt;';\r\n\u00a0\u00a0 \u00a0echo '&lt;ul&gt;';\r\n\r\n\u00a0\u00a0 \u00a0foreach ($data as $name =&gt; $value) {\r\n\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0echo \"&lt;li&gt;$name: \";\r\n\r\n\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0if (is_array($value)) {\r\n\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0$value = implode(', ', $value);\r\n\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0}\r\n\r\n\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0echo \"&lt;b&gt;$value&lt;\/b&gt;\";\r\n\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0echo '&lt;\/li&gt;';\r\n\u00a0\u00a0 \u00a0}\r\n\r\n\u00a0\u00a0 \u00a0echo '&lt;\/ul&gt;';\r\n}\r\n\r\n\/\/ Flow starts here.\r\n\r\ncheckGETParametersOrDie([\r\n\u00a0\u00a0\u00a0 'name',\r\n\u00a0\u00a0\u00a0 'programming-languages'\r\n]);\r\n\r\n$name = $_GET['name'];\r\n$programmingLanguages = $_GET['programming-languages']; \/\/ An array.\r\n\r\nprintData([\r\n\u00a0\u00a0 \u00a0'Name' =&gt; $name,\r\n\u00a0\u00a0 \u00a0'Programming languages you have worked with' =&gt; $programmingLanguages\r\n]);<\/pre>\n<p>The way of retrieving the data is exactly the same (line 46), but in this case we have to be aware that we are receiving an array.<\/p>\n<p>Because of this, when printing the form data (or doing anything else), we have to know if we are dealing with an array or not. For this, we have to check explicitly if it is an array, with <code>is_array()<\/code> function, to then manage it as appropriate. In this case, we just implode it to a string.<\/p>\n<p>So, the script could generate an output like the following:<\/p>\n<blockquote><p>You have submitted the form with the following data:<\/p>\n<ul>\n<li>Name: <b>Julen<\/b><\/li>\n<li>Programming languages you have worked with: <b>PHP, Other<\/b><\/li>\n<\/ul>\n<\/blockquote>\n<h2>4. Generating checkbox structures dynamically<\/h2>\n<p>It&#8217;s worth mentioning how we could generate checkbox structures dynamically for a given data structure, that can be achieved with a script like the following:<\/p>\n<p><span style=\"text-decoration: underline;\"><em>generate_checkboxes.php<\/em><\/span><\/p>\n<pre class=\"brush:php\">&lt;?php\r\n\r\n\/**\r\n\u00a0* Generates checkboxes, for group =&gt; values =&gt; checked\/unchecked structures,\r\n\u00a0* wrapping each group in a fieldset.\r\n\u00a0*\r\n\u00a0* @param array $data The data to create the checkboxes for.\r\n\u00a0* @return string The generated checkboxes.\r\n\u00a0*\/\r\nfunction generateCheckboxes($data) {\r\n\u00a0\u00a0\u00a0 $checkboxes = '';\r\n\r\n\u00a0\u00a0\u00a0 foreach ($data as $group =&gt; $values) {\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 $fieldset = $values['fieldset'];\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 $options = $values['options'];\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 $checkboxes .= '&lt;fieldset&gt;';\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 $checkboxes .= \"&lt;legend&gt;$fieldset&lt;\/legend&gt;\";\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 foreach ($options as $option =&gt; $checked) {\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 $checked = ($checked) ? 'checked' : '';\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 $checkboxes .= '&lt;div&gt;';\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 $checkboxes .= \"&lt;input type='checkbox' name='$group\" . '[]' . \"' id='$option' value='$option' $checked&gt;\";\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 $checkboxes .= \"&lt;label for='$option'&gt;$option&lt;\/label&gt;\";\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 $checkboxes .= '&lt;\/div&gt;';\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 }\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 $checkboxes .= '&lt;\/fieldset&gt;';\r\n\u00a0\u00a0\u00a0 }\r\n\r\n\u00a0\u00a0\u00a0 return $checkboxes;\r\n}<\/pre>\n<p>Placing each checkbox group inside a fieldset (which is not actually necessary, just structure matters).<\/p>\n<p>The following snippet shows an input data example for this function, which would generate the same output as the shown in section 2:<\/p>\n<p><span style=\"text-decoration: underline;\"><em>generate_radiobuttons.php<\/em><\/span><\/p>\n<pre class=\"brush:php\">\/\/ ...\r\n\r\n$programmingLanguages = [\r\n\u00a0\u00a0\u00a0 'programming-languages' =&gt; [\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 'fieldset' =&gt; 'Programming languages you have worked with',\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 'options' =&gt; [\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 'Python' =&gt; false,\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 'PHP' =&gt; true,\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 'Haskell' =&gt; false,\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 'Other' =&gt; false\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 ]\r\n\u00a0\u00a0\u00a0 ]\r\n];\r\n\r\n$checkboxes = generateCheckboxes($programmingLanguages);\r\n\r\necho $checkboxes;\r\n\r\necho 'Generated HTML code:&lt;br&gt;';\r\necho \"&lt;xmp&gt;$checkboxes&lt;\/xmp&gt;\";<\/pre>\n<h2>5. Summary<\/h2>\n<p>In this example we have seen how to manage the checkbox elements with PHP, paying attention at the way of retrieving the values of a checkbox group, which is different from retrieving other input types, since they are defined as arrays. We have also seen how to generate checkbox structures dynamically with a simple PHP function that generates the HTML code from a data structure.<\/p>\n<h2>6. Download the source code<\/h2>\n<p>This was an example of checkboxes with PHP.<\/p>\n<div class=\"download\"><strong>Download<\/strong><br \/>\nYou can download the full source code of this example here: <a href=\"http:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2016\/08\/PHPCheckboxExample.zip\"><strong>PHPCheckboxExample<\/strong><\/a><\/div>\n","protected":false},"excerpt":{"rendered":"<p>Checkboxes are those HTML elements that behave like toggle switches. So, unlike the radio buttons, checkboxes do not enforce to select an option from a group of options; we can select as much as we want. In this example, we will see how to deal with these checkboxes in PHP. For this example, we will &hellip;<\/p>\n","protected":false},"author":160,"featured_media":930,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[10],"tags":[182,176],"class_list":["post-14419","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-php","tag-checkbox","tag-form"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.5 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>PHP Checkbox Example - Web Code Geeks - 2026<\/title>\n<meta name=\"description\" content=\"Checkboxes are those HTML elements that behave like toggle switches. So, unlike the radio buttons, checkboxes do not enforce to select an option from a\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.webcodegeeks.com\/php\/php-checkbox-example\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"PHP Checkbox Example - Web Code Geeks - 2026\" \/>\n<meta property=\"og:description\" content=\"Checkboxes are those HTML elements that behave like toggle switches. So, unlike the radio buttons, checkboxes do not enforce to select an option from a\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.webcodegeeks.com\/php\/php-checkbox-example\/\" \/>\n<meta property=\"og:site_name\" content=\"Web Code Geeks\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/webcodegeeks\" \/>\n<meta property=\"article:published_time\" content=\"2016-08-17T13:15:48+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2018-01-09T08:40:04+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/10\/php-logo.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"150\" \/>\n\t<meta property=\"og:image:height\" content=\"150\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Toni\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@webcodegeeks\" \/>\n<meta name=\"twitter:site\" content=\"@webcodegeeks\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Toni\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"6 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/www.webcodegeeks.com\/php\/php-checkbox-example\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/php\/php-checkbox-example\/\"},\"author\":{\"name\":\"Toni\",\"@id\":\"https:\/\/www.webcodegeeks.com\/#\/schema\/person\/54a7be647b0b871cff41cbf3d2a95966\"},\"headline\":\"PHP Checkbox Example\",\"datePublished\":\"2016-08-17T13:15:48+00:00\",\"dateModified\":\"2018-01-09T08:40:04+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/php\/php-checkbox-example\/\"},\"wordCount\":667,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/#organization\"},\"image\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/php\/php-checkbox-example\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/10\/php-logo.jpg\",\"keywords\":[\"checkbox\",\"form\"],\"articleSection\":[\"PHP\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/www.webcodegeeks.com\/php\/php-checkbox-example\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.webcodegeeks.com\/php\/php-checkbox-example\/\",\"url\":\"https:\/\/www.webcodegeeks.com\/php\/php-checkbox-example\/\",\"name\":\"PHP Checkbox Example - Web Code Geeks - 2026\",\"isPartOf\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/php\/php-checkbox-example\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/php\/php-checkbox-example\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/10\/php-logo.jpg\",\"datePublished\":\"2016-08-17T13:15:48+00:00\",\"dateModified\":\"2018-01-09T08:40:04+00:00\",\"description\":\"Checkboxes are those HTML elements that behave like toggle switches. So, unlike the radio buttons, checkboxes do not enforce to select an option from a\",\"breadcrumb\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/php\/php-checkbox-example\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.webcodegeeks.com\/php\/php-checkbox-example\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.webcodegeeks.com\/php\/php-checkbox-example\/#primaryimage\",\"url\":\"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/10\/php-logo.jpg\",\"contentUrl\":\"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/10\/php-logo.jpg\",\"width\":150,\"height\":150},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.webcodegeeks.com\/php\/php-checkbox-example\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.webcodegeeks.com\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"PHP\",\"item\":\"https:\/\/www.webcodegeeks.com\/category\/php\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"PHP Checkbox Example\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.webcodegeeks.com\/#website\",\"url\":\"https:\/\/www.webcodegeeks.com\/\",\"name\":\"Web Code Geeks\",\"description\":\"Web Developers Resource Center\",\"publisher\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.webcodegeeks.com\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/www.webcodegeeks.com\/#organization\",\"name\":\"Exelixis Media P.C.\",\"url\":\"https:\/\/www.webcodegeeks.com\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.webcodegeeks.com\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png\",\"contentUrl\":\"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png\",\"width\":864,\"height\":246,\"caption\":\"Exelixis Media P.C.\"},\"image\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/webcodegeeks\",\"https:\/\/x.com\/webcodegeeks\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.webcodegeeks.com\/#\/schema\/person\/54a7be647b0b871cff41cbf3d2a95966\",\"name\":\"Toni\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.webcodegeeks.com\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/21c1661474c78b4757355b8beef9ab1d14f490ee3a3e67392f4e618d36643d4c?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/21c1661474c78b4757355b8beef9ab1d14f490ee3a3e67392f4e618d36643d4c?s=96&d=mm&r=g\",\"caption\":\"Toni\"},\"url\":\"https:\/\/www.webcodegeeks.com\/author\/julen-pardo\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"PHP Checkbox Example - Web Code Geeks - 2026","description":"Checkboxes are those HTML elements that behave like toggle switches. So, unlike the radio buttons, checkboxes do not enforce to select an option from a","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.webcodegeeks.com\/php\/php-checkbox-example\/","og_locale":"en_US","og_type":"article","og_title":"PHP Checkbox Example - Web Code Geeks - 2026","og_description":"Checkboxes are those HTML elements that behave like toggle switches. So, unlike the radio buttons, checkboxes do not enforce to select an option from a","og_url":"https:\/\/www.webcodegeeks.com\/php\/php-checkbox-example\/","og_site_name":"Web Code Geeks","article_publisher":"https:\/\/www.facebook.com\/webcodegeeks","article_published_time":"2016-08-17T13:15:48+00:00","article_modified_time":"2018-01-09T08:40:04+00:00","og_image":[{"width":150,"height":150,"url":"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/10\/php-logo.jpg","type":"image\/jpeg"}],"author":"Toni","twitter_card":"summary_large_image","twitter_creator":"@webcodegeeks","twitter_site":"@webcodegeeks","twitter_misc":{"Written by":"Toni","Est. reading time":"6 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.webcodegeeks.com\/php\/php-checkbox-example\/#article","isPartOf":{"@id":"https:\/\/www.webcodegeeks.com\/php\/php-checkbox-example\/"},"author":{"name":"Toni","@id":"https:\/\/www.webcodegeeks.com\/#\/schema\/person\/54a7be647b0b871cff41cbf3d2a95966"},"headline":"PHP Checkbox Example","datePublished":"2016-08-17T13:15:48+00:00","dateModified":"2018-01-09T08:40:04+00:00","mainEntityOfPage":{"@id":"https:\/\/www.webcodegeeks.com\/php\/php-checkbox-example\/"},"wordCount":667,"commentCount":0,"publisher":{"@id":"https:\/\/www.webcodegeeks.com\/#organization"},"image":{"@id":"https:\/\/www.webcodegeeks.com\/php\/php-checkbox-example\/#primaryimage"},"thumbnailUrl":"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/10\/php-logo.jpg","keywords":["checkbox","form"],"articleSection":["PHP"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.webcodegeeks.com\/php\/php-checkbox-example\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.webcodegeeks.com\/php\/php-checkbox-example\/","url":"https:\/\/www.webcodegeeks.com\/php\/php-checkbox-example\/","name":"PHP Checkbox Example - Web Code Geeks - 2026","isPartOf":{"@id":"https:\/\/www.webcodegeeks.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.webcodegeeks.com\/php\/php-checkbox-example\/#primaryimage"},"image":{"@id":"https:\/\/www.webcodegeeks.com\/php\/php-checkbox-example\/#primaryimage"},"thumbnailUrl":"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/10\/php-logo.jpg","datePublished":"2016-08-17T13:15:48+00:00","dateModified":"2018-01-09T08:40:04+00:00","description":"Checkboxes are those HTML elements that behave like toggle switches. So, unlike the radio buttons, checkboxes do not enforce to select an option from a","breadcrumb":{"@id":"https:\/\/www.webcodegeeks.com\/php\/php-checkbox-example\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.webcodegeeks.com\/php\/php-checkbox-example\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.webcodegeeks.com\/php\/php-checkbox-example\/#primaryimage","url":"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/10\/php-logo.jpg","contentUrl":"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/10\/php-logo.jpg","width":150,"height":150},{"@type":"BreadcrumbList","@id":"https:\/\/www.webcodegeeks.com\/php\/php-checkbox-example\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.webcodegeeks.com\/"},{"@type":"ListItem","position":2,"name":"PHP","item":"https:\/\/www.webcodegeeks.com\/category\/php\/"},{"@type":"ListItem","position":3,"name":"PHP Checkbox Example"}]},{"@type":"WebSite","@id":"https:\/\/www.webcodegeeks.com\/#website","url":"https:\/\/www.webcodegeeks.com\/","name":"Web Code Geeks","description":"Web Developers Resource Center","publisher":{"@id":"https:\/\/www.webcodegeeks.com\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.webcodegeeks.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.webcodegeeks.com\/#organization","name":"Exelixis Media P.C.","url":"https:\/\/www.webcodegeeks.com\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.webcodegeeks.com\/#\/schema\/logo\/image\/","url":"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","contentUrl":"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","width":864,"height":246,"caption":"Exelixis Media P.C."},"image":{"@id":"https:\/\/www.webcodegeeks.com\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/webcodegeeks","https:\/\/x.com\/webcodegeeks"]},{"@type":"Person","@id":"https:\/\/www.webcodegeeks.com\/#\/schema\/person\/54a7be647b0b871cff41cbf3d2a95966","name":"Toni","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.webcodegeeks.com\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/21c1661474c78b4757355b8beef9ab1d14f490ee3a3e67392f4e618d36643d4c?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/21c1661474c78b4757355b8beef9ab1d14f490ee3a3e67392f4e618d36643d4c?s=96&d=mm&r=g","caption":"Toni"},"url":"https:\/\/www.webcodegeeks.com\/author\/julen-pardo\/"}]}},"_links":{"self":[{"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/posts\/14419","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/users\/160"}],"replies":[{"embeddable":true,"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/comments?post=14419"}],"version-history":[{"count":0,"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/posts\/14419\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/media\/930"}],"wp:attachment":[{"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/media?parent=14419"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/categories?post=14419"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/tags?post=14419"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}