【发布时间】:2009-12-11 06:08:50
【问题描述】:
我在编辑表单中使用了多选框,使用“in-array($needle,$haystack)”php函数在其中显示以前选择的项目,但如果变量数组“$haystack”存储了多个值,没有值,我收到警告消息,提示“in-array($needle,$haystack)”中的第二个参数的数据类型错误
我的选择框代码如下:
**<select name="otherdiseases[]" id="otherdiseases" class="list-menu" multiple="multiple">
<option value=''>Other Medical Diseases</option>
<option value='Prior heart Attack'<?php if(count($res_user[0]['otherdiseases'])!=0){ if(in_array('Prior heart Attack',$res_user[0]['otherdiseases'])){ ?> selected="selected" <?php } }?>>Prior heart Attack</option>
<option value='Ischemic Heart Attack'<?php if(count($res_user[0]['otherdiseases'])!=0){ if(in_array('Ischemic Heart Attack',$res_user[0]['otherdiseases'])){ ?> selected="selected" <?php } }else{ ?> selected=""<?php }?>>Ischemic Heart Attack</option>
<option value='Stroke' <?php if(count($res_user[0]['otherdiseases'])!=0){ if(in_array('Stroke',$res_user[0]['otherdiseases'])){ ?> selected="selected" <?php } }?> >Stroke</option>
<option value='Dialysis' <?php if(count($res_user[0]['otherdiseases'])!=0){ if(in_array('Dialysis',$res_user[0]['otherdiseases'])){ ?> selected="selected" <?php } }?> >Dialysis</option>
<option value='High BP' <?php if(count($res_user[0]['otherdiseases'])!=0){ if(in_array('High BP',$res_user[0]['otherdiseases'])){ ?> selected="selected" <?php } }?> >High BP</option>
<option value='High Cholesterol' <?php if(count($res_user[0]['otherdiseases'])!=0){ if(in_array('High Cholesterol',$res_user[0]['otherdiseases'])){ ?> selected="selected" <?php } }?> >High Cholesterol</option>
<option value='Thyroid' <?php if(count($res_user[0]['otherdiseases'])!=0){ if(in_array('Thyroid',$res_user[0]['otherdiseases'])){ ?> selected="selected" <?php } }?> >Thyroid</option>
<option value='Previous Eye Laser Therapy' <?php if(count($res_user[0]['otherdiseases'])!=0){ if(in_array('Previous Eye Laser Therapy',$res_user[0]['otherdiseases'])){ ?> selected="selected" <?php } }?> >Previous Eye Laser Therapy</option>
<option value='Foot Surgeries' <?php if(count($res_user[0]['otherdiseases'])!=0){ if(in_array('Foot Surgeries',$res_user[0]['otherdiseases'])){ ?> selected="selected" <?php } }?> >Foot Surgeries</option>
</select>**
在上面的代码中,变量数组 $res_user[0]['otherdiseases'] 是从一个选择查询中提取的,我已经使用 var_dump 交叉检查了它的值...
当$res_user[0]['otherdiseases']中的值为0时,请帮我纠正我的情况......以避免上述警告......
【问题讨论】: