PHP if语句具有多个值

Ric*_*ler 5 php if-statement

是否有更短的写作方式?

<? 
if($_GET['id']==1 ||
$_GET['id']==3 ||
$_GET['id']==4 || 
$_GET['id']==5)
{echo 'does it really have to be this explicit?'};
?>
Run Code Online (Sandbox Code Playgroud)

也许这样的事情?

<?
if($_GET['id']==1 || 3 || 4 || 5){echo 'this is much shorter'};
?>
Run Code Online (Sandbox Code Playgroud)

hsz*_*hsz 25

试试:

if ( in_array($_GET['id'], array(1, 3, 4, 5)) ) {}
Run Code Online (Sandbox Code Playgroud)