三元运算

//三元运算
function getParam($param, $type, $default = '')
{
	switch ($type)
	{
		case 'POST' :
			$result = lib_replace_end_tag(trim($_POST[$param]));
			break;

		case 'GET' :
			$result = lib_replace_end_tag(trim($_GET[$param]));
			break;

		default :
			$result = lib_replace_end_tag(trim($_POST[$param] ? $_POST[$param] : $_GET[$param]));
			break;
	}
	$result = $result == '' ? $default : $result;
	return $result;
}


POST:
getParam('yunli', 'post', '普通');
GET :
getParam('yunli', 'get', '普通');


$title = getParam('title', 'get', '标题');
$yunli = getParam('yunli', 'post', '普通');
$email = getParam('email', 'post');//不用默认值

posted @ 2012-12-10 06:38  网络剑客  阅读(175)  评论(0)    收藏  举报