有更短的写作方法吗?
<?
if($_GET['id']==1 ||
$_GET['id']==3 ||
$_GET['id']==4 ||
$_GET['id']==5)
{echo 'does it really have to be this explicit?'};
?>也许是这样的?
<?
if($_GET['id']==1 || 3 || 4 || 5){echo 'this is much shorter'};
?>发布于 2013-10-02 14:30:09
只需试着:
if ( in_array($_GET['id'], array(1, 3, 4, 5)) ) {}发布于 2013-10-02 14:35:44
也许不是更短,但更易读。尝试in_array()函数:
if (in_array($_GET['id'], array(1, 3, 4, 5)))
{
echo "What about this?";
}发布于 2013-10-02 14:33:33
也许切换会有帮助
switch($_GET['id']) {
case 1:
case 3:
case 4:
case 5:
echo 'Slect maybe :P';
break;
}https://stackoverflow.com/questions/19139453
复制相似问题