一个很简单的有关问题

WBOY
Release: 2016-06-13 13:48:39
Original
887 people have browsed it

一个很简单的问题
前台有两个复选框




后台取它数据
$a = $_POST['hobby'];
我的问题是,假如没有选中hobby就没有这个值,但我希望是,没有选择中的话,有个默认值是0.应该怎么办

------解决方案--------------------
按你说的做就好了,

if(没有这个值)
$a=0;
------解决方案--------------------
这样提交过来是空吗?我几乎没这么写过表单.如果是空的话,那就用empty()来判断.

------解决方案--------------------
没有选中的checkbox不会被提交

PHP code
$a = array_fill(1, 10, 0);
if($_POST['hobby'])
  foreach($_POST['hobby'] as $v) $a[$v] = 1;
print_r($a);
<br><font color="#e78608">------解决方案--------------------</font><br>
Copy after login
探讨

但问题是在于我想用数组,还有你怎么知道有没有选中
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template