PHP Nested Loop - Comparing each item in two arrays and outputting them as checked or unchecked textboxes
I think the title explains most of it. The items of the two arrays that I know are matching strings do not come out as checked checkboxes. What I have:
*Edit: realized I was using the wrong array. However, now I'm only getting the first entry right because of th breaks.
<?php
foreach ($list as $x){
foreach ($arr as $y){
if ($x == $y){
echo '<li>';
echo '<input type="checkbox" checked="checked" value="'.$x开发者_StackOverflow社区.'" />'.$x.'<br/>';
echo '</li>';
break;
}
else {
echo '<li>';
echo '<input type="checkbox" value="'.$x.'" />'.$x.'<br/>';
echo '</li>';
break;
}
}
}
echo '</ul>';
?>
Did you tried the script without the break;
part?
It is quite weird that you use the breaks there.
Moreover, do you also open <ul>
somewhere?
It is not very clear what you want, please be more specific.
精彩评论