php echo if two conditions are true

99封情书 提交于 2019-12-04 03:11:29
if (!empty($id) && file_exists($filename))

Just use the AND or && operator to check two conditions:

if (file_exists($filename) AND ! empty($id)): // do something

It's fundamental PHP. Reading material:

http://php.net/manual/en/language.operators.logical.php

http://www.php.net/manual/en/language.operators.precedence.php

You need the logical AND operator:

if (file_exists($filename) AND !empty($id)) {
    echo $player;
}
if (file_exists($filename) && !empty($id)){
   echo $player;
}else{
   echo 'other text';
}

you need to check $id along with file_exists($filename) as follows

if (file_exists($filename) && $id != '') {
echo $player;

} else { 
echo 'something';
}

Using ternary operator:

echo (!empty($id)) && file_exists($filename) ? 'OK' : 'not OK';

Using if-else clause:

if ( (!empty($id)) && file_exists($filename) ) {
    echo 'OK';
} else {
    echo 'not OK';
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!