/**
* 取得提交的数据
* @param unknown $data
* @param string $method
* @return mixed
* $test = input(array('platform'=>'平台', 'bankcode'=>array('without', 1001), 'money'=>array('egt', 100, '充值至少100元')), 'post');
* $test = input('platform', 'bankcode', 'money', 'get');
*/
function input($data, $method='post'){
if(is_string($data)){
$data = func_get_args(); $method = array_pop($data);
}
if(empty($method)) $method = 'param';
foreach($data as $field => $options){
if(is_numeric($field)){
$field = $options; $options = array('without', '');
}
if(!is_array($options)){
$options = array('neq', '', $options .'不能为空');
}
$return[$field] = $value = I($method. '.' .$field, $options[1]);
if(empty($options[2])) $options[2] = '参数验证不合法';
$info = '';
switch($options[0]){
case 'eq' : if($value != $options[1]) $info = $options[2];
break;
case 'neq': if($value == $options[1]) $info = $options[2];
break;
case 'lt' : if($value >= $options[1]) $info = $options[2];
break;
case 'gt' : if($value <= $options[1]) $info = $options[2];
break;
case 'elt': if($value > $options[1]) $info = $options[2];
break;
case 'egt': if($value < $options[1]) $info = $options[2];
break;
case 'without':
break;
default: $info = '比较类型不合法';
}
//if(!empty($info)) $return['errors'][$field] = $info;//所有错误消息
}
if(!empty($info)) $return['error'] = $info;
return $return;
} 最佳答案