开发者

PHP Nested Loop - Comparing each item in two arrays and outputting them as checked or unchecked textboxes

开发者 https://www.devze.com 2023-03-31 15:33 出处:网络
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:

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号