【发布时间】:2009-09-03 04:24:35
【问题描述】:
<?PHP
$signup_errors = array();
$signup_errors['captcha'] = 'test 1';
$signup_errors['something'] = 'test 2';
$signup_errors['another'] = 'test 3';
$signup_errors['getthepoint'] = 'test 4';
//this would work
if (isset($signup_errors) && in_array('test 4', $signup_errors)){
echo 'it works';
}
//However I need something like this to work
if (isset($signup_errors) && in_array('captcha', $signup_errors)){
echo 'it works';
}
?>
这里的最终目标是有一个 html 表单,我可以在其中更改 css div 类名是否存在错误数组项,所以如果它返回这个
$signup_errors['captcha'] = 'Please enter the correct security code';
然后在提交的表单上我会有这样的东西
<input type="text" class="textarealong <?PHP if (isset($signup_errors) && in_array('captcha', $signup_errors)){echo 'error-class';}?> " value=''>
【问题讨论】: