【发布时间】:2010-11-25 10:05:50
【问题描述】:
我在一个页面上多次绑定不同的表单项,我只在存在 error_array 键的情况下将 css div 类插入表单项,这就是我突出显示其中有错误的表单项的方式.
工作,如果我有一个错误很好,因为我的错误数组被设置,问题是在设置错误之前,它试图寻找一个不存在的数组键。我在想首先使用 php 的 isset 函数将是票,但我想你不能将 isset 与另一个函数结合起来?
<?php
//this works
$search_array = array('first' => 1, 'second' => 4);
if (array_key_exists('first', $search_array)){
echo "good";
}
// this does not work, will give write errors
$search_array = array('first' => 1, 'second' => 4);
if (isset(array_key_exists('first', $search_array))){
echo "good";
}
// Here is 1 example how I need to make the end result work
$country_class = (array_key_exists('country', $signup_errors)) ? ' signup_error' : ' signup_good';
echo '<select name="country" id="country" class="textarealong ' .$country_class. '"/>';
?>
其他部分我是这样用的
<?PHP echo(array_key_exists('password', $signup_errors)) ? ' signup_error' : ' signup_good';?>
如果可能的话,我需要将其设为 1 行代码
【问题讨论】: