so i have 2 lists i need to compare

$list = array("Apple", "Orange", "Lemon", "Candy");

and

$db = $r_bio['other'];
$db2 = explode(":", $db);

i want to compare the two and if i find the same i want to echo a checked checkbox if not an unchecked checkbox

if($db2 == $list)
{ echo "<input type=checkbox checked value=$list />$list"; } else { echo "<input type=checkbox value=$list /> $list"; }

the $db2 can contain 1, 2, ..., or all of the items in the $list

You can use a loop with in_array():

foreach($db2 as $key)
{
    echo in_array($key, $list) ? "<input type='checkbox' checked value='$list' />$list" : "<input type='checkbox' value='$list' /> $list";
}

More information: http://php.net/in_array

That works....50%
it only echo's out the values that exits in $db2(the checked ones)
i need to print the rest too(the unchecked ones)

Cereal gave you 100% solution, it will print both check and not checked values

Then reverse it:

foreach($list as $key)
{
    echo in_array($key, $db2) ? "<input type='checkbox' checked value='$key' />$key" : "<input type='checkbox' value='$key' /> $key";
}

yes....thats works....thank you

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.