I have an string in database : 3,8,10,15
and in script i have an array : $a=array(0=>'music',1=>'computers'....etc), the keys are matching the strings in database.
Then i explode() the string from database with: $a=explode(",",$dbresult)
This makes an array like this:
$a =
Array
(
[0] => 3
[1] => 8
[2] => 10
[3] => 15
)
In script:
<?PHP
$b=array(0=>'music',1=>'Computers','...etc');
$a = explode(",",$a);
foreach ( $b as $key => $value ){
$select = $a==$key ? " checked='checked'" : null;
echo "<label><input type='checkbox' name='name' value='{$key}'$select/> {$value};
}}
?>
This ofcourse will not work since its matching the $b arrays keys, and not the values of $a
So my question is.. How can i make it match the $b keys against $a values ?
$aand$b. Are the keys supposed to align between them such that$a[0] (3)is related to$b[0] (music)?$arelate to the keys of$bsuch that$a[0] (3)relates to$b[3] ('someotherthing')?