Home » Show Multiple Checkbox Checked With Multiple Array Using Php

Show Multiple Checkbox Checked With Multiple Array Using Php

We are telling you by our best web post that how to show multiple checkboxes checked with multiple arrays using PHP Example.

Whenever you can checkbox checked with using the MySQL database then some users say it is the very difficulty not user friendly. but our article through you would easily step by step understand.

how to show multiple checkbox checked in php?

We will get to product information from the database and display different product information with the checkbox. how to display checked checkbox value in php? we selected product information inserts into another database. we need to inserted product information at edit time. because if already exists in the database and then the HTML checkbox should be checked in the edit form. below example in, the select_products array converts into the string with comma sign as well as explode function by string to convert into the array. if match array value after that the HTML checkbox will be checked or the HTML checkbox will be unchecked.

Read Also:  Laravel Complex queries using Eloquent Query

Also Read: PHP Multiple Checkbox Array Handling Tutorial Example

index.php

<?php
       // select product value
	$select_products = array (
	  array("name"=>"Mobile","value"=>1),
	  array("name"=>"Laptop","value"=>2)
	);

       // product information
        $products_detail = array (
		array("name"=>"Mobile","value"=>1),
		array("name"=>"Laptop","value"=>2),
		array("name"=>"DVD","value"=>3),
		array("name"=>"Pendrive","value"=>4)
	);

	$string="";
	foreach ($select_products as  $key => $val) {
		$string .= ',' .$val['value'];
	}
	$string = substr($string,1);
	$string = explode(',',$string);

	foreach ($products_detail as $ld)
        {
		if(in_array($ld['value'],$string))
		{
		?>
		    <div class="form-group" style="margin-bottom: 0px;">
			    <input type="checkbox" name="products[]" checked value="<?php echo $ld['value']; ?>">
		        <label><?php echo $ld['name']; ?></label>
		     </div>
		<?php
		} else
		{
		?>
		   <div class="form-group" style="margin-bottom: 0px;">
		       <input type="checkbox" name="products[]" value="<?php echo $ld['value']; ?>">
		       <label><?php echo $ld['name']; ?></label>
		    </div>
		<?php
		}
	}
?>


Related FAQ

Here are some more FAQ related to this Article:

  1. Read Also:  Paytm Payment Gateway Integration in PHP step By step
  2. Read Also:  Simple Laravel Contact Us Form With Email Example
  3. Read Also:  jquery Pass PHP Laravel 5.6 Variables to Javascript
  4. Read Also:  PHP woocommerce_single_product_summary wordpress function
  5. Read Also:  How TO Check if checkbox is checked with jQuery?
  6. Read Also:  MySQL sample database file extension and location
  7. Read Also:  Morris.js Dynamic Data Example PHP Mysql
  8. Read Also:  Session Flash Messages in Laravel 6 Tutorial
  9. Read Also:  PHP Laravel 7 Send Email Example Tutorial
  10. Read Also:  Laravel 6 CONCAT Multiple Columns with example

Leave a Comment

Your email address will not be published. Required fields are marked *