Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

php echo if two conditions are true

The actual code looks like this:

if (file_exists($filename)) {echo $player;

} else { 

echo 'something';

but it displays the player even if the id is not called from the url

i need something like this:

check if $filename exists and $id it is not empty then echo $player

if else echo something else

i check if $id is not empty with

if(empty($id)) echo "text";

but i don't know how to combine both of them

Can somebody help me?

Thank you for all your code examples but i still have a problem:

How i check if $id is not empty then echo the rest of code

like image 396
m3tsys Avatar asked May 08 '11 13:05

m3tsys


People also ask

What does ?: Mean in PHP?

The Scope Resolution Operator (also called Paamayim Nekudotayim) or in simpler terms, the double colon, is a token that allows access to static, constant, and overridden properties or methods of a class.

What is nested IF ELSE statement in PHP?

The nested if statement contains the if block inside another if block. The inner if statement executes only when specified condition in outer if statement is true.

Does PHP have if statements?

In PHP we have the following conditional statements: if statement - executes some code if one condition is true. if...else statement - executes some code if a condition is true and another code if that condition is false. if...elseif...else statement - executes different codes for more than two conditions.

How do you end an if statement in PHP?

The endif keyword is used to mark the end of an if conditional which was started with the if(...): syntax. It also applies to any variation of the if conditional, such as if... elseif and if...else .


2 Answers

if (!empty($id) && file_exists($filename))
like image 184
Pentium10 Avatar answered Sep 30 '22 23:09

Pentium10


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

like image 23
Wesley Murch Avatar answered Sep 30 '22 23:09

Wesley Murch