Web Development

How to show checkbox checked in PHP

<?php
$country = array( 1 => ‘USA’, 2 => ‘UK’, 3 => ‘Japan’, 4 => ‘India’, 5 => ‘Australia’);
$the_key = ‘Australia|UK|India’; // or whatever you want
$myrow = explode(‘|’,$the_key);
$containsSearch1 = array_intersect( $country,$myrow);

foreach($country as $key=> $val)
{
if(in_array($val,$containsSearch1)) { echo “$val.<input type=’checkbox’ name=’check_list[]’ value='”.$val.”‘ checked=’checked’ /><br />”; }
else { echo “$val.<input type=’checkbox’ name=’check_list[]’ value='”.$val.”‘  /><br />”; }
}
?>

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s