缩短php如果else阻止 [英] shortened php if else block

查看:83
本文介绍了缩短php如果else阻止的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果不这样做,那么短路是什么?我曾经在某处看过它,但记不起来了.

what is the shorted if else block for this. I seen it somewhere before but cant remember it.

if (isset($_POST['value')){
 $value = $_POST['value'];
} elseif (isset($_GET['value'])){
 $value = $_GET['value'];
} else {
 $value = '';
}

推荐答案

您是指使用$ _REQUEST全局数组而不是同时检查$ _POST和$ _GET吗?如果是这样,应该是:

Are you referring to using the $_REQUEST global array instead of checking both $_POST and $_GET? If so, it should be:

if(isset($_REQUEST['value']))
{
    $value = $_REQUEST['value'];
}else
    $value = '';

或三元形式:

$value = isset($_REQUEST['value']) ? $_REQUEST['value'] : '';

这篇关于缩短php如果else阻止的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆