
例如默认值为“不启用”,那么这个 value 设定为 -1 还是 0 比较好?
<?php $default_enable = -1 // or 0? $checked span class="o">= $default_enable === -1 ? ' checked ' : null; // or === 0? ?> <input type="checkbox" value="<?php echo $default_enable;?>" <?php echo $checked;?> /> 1 abelyao 2015 年 2 月 13 日 删了 < 0,禁用 = 0,可用 > 0 目前几个项目都啥这样表示,其实怎样都好,全项目统一就好 |
2 suliuyes 2015 年 2 月 13 日 跟楼上一样。一般我是,0和1表示开关,0是关闭禁用,1是启用,-1表示删除之类的不可用状态。 |
3 lujiajing1126 2015 年 2 月 13 日 默认值一般是0 可以参考FLAGS系统 |
4 icedx 2015 年 2 月 13 日 一般都是0 |
5 yksoft1 2015 年 2 月 13 日 习惯使用C/C++的,禁用肯定会定义于0 |
6 miaoever 2015 年 2 月 13 日 用 0 可以用 unsigned int 存储, -1 就只能是 signed int 了。 |
7 lincanbin &nbp; 2015 年 2 月 14 日 0 如果你用0的话,你可以这么写: $checked = $default_enable ? ' checked ' : null; 不过你为什么不用bool呢? |
8 lincanbin 2015 年 2 月 14 日 PHP官方指定了true=1, false=0 echo intval(false);//0 echo intval(true);//1 所以你可以这样: <?php $default_enable = 0; $checked = $default_enable ? ' checked ' : null; ?> <input type="checkbox" value="<?php echo $default_enable;?>" <?php echo $checked;?> /> 也可以这样: <?php $default_enable = false; $checked = $default_enable ? ' checked ' : null; ?> <input type="checkbox" value="<?php echo intval($default_enable); ?>" <?php echo $checked; ?> /> |