1

我想使用 for显示数组值,后跟checkbox一个 html 内部:tableloop

<?php
    for ($j = 0; $j < $data['user']['droit']['cnt']; $j++)
    {
?>
        <table>
            <tr>
                <td><?php echo $data['user']['droit'][$j]['menu_titre']; ?></td>
                <?php
                    $checked = "";
                    if (is_array($data['user_droit']) && count($data['user_droit']) > 0 && in_array($data['user']['droit'][$j]['menu_code'], $data['user_droit']))
                        $checked = " checked ";
                ?>
                <td><input type="checkbox" name="<?php echo $data['user']['droit'][$j]['menu_code']; ?>" 
                           value="<?php echo $data['user']['droit'][$j]['menu_code']; ?>" <?php echo $checked ?> />
                </td>
            </tr>
        </table>
<?php
    }
?>

disabled如果从循环中检查它,我不知道如何使单个复选框成为。如何做到这一点?

4

1 回答 1

1

或设置$checked = " checked disabled ";

    <?php
        for ($j = 0; $j < $data['user']['droit']['cnt']; $j++)
        {
    ?>
            <table>
                <tr>
                    <td><?php echo $data['user']['droit'][$j]['menu_titre']; ?></td>
                    <?php
                        $checked = "";
                        if (is_array($data['user_droit']) && count($data['user_droit']) > 0 && in_array($data['user']['droit'][$j]['menu_code'], $data['user_droit']))
                        {
                            $checked = " checked disabled ";
                        }
                    ?>
                    <td><input type="checkbox" name="<?php echo $data['user']['droit'][$j]['menu_code']; ?>" 
                               value="<?php echo $data['user']['droit'][$j]['menu_code']; ?>" <?php echo $checked ?> />
                    </td>
                </tr>
            </table>
    <?php
        }
    ?>
于 2012-06-08T12:19:35.970 回答