Jump to content

Mulitple conditions in IF statement


eddy556

Recommended Posts

Hi, I need help on how to use multiple conditions within an IF statement.

 

Through research I have found that you and test if both conditions are true using && but I need to test for OR.

 

I was thinking it should look something like: 

if($filetype != ".mp3" || $filetype != ".MP3")

and this doesn't throw an error.  I'm sure its simple.

 

Thanks!

Link to comment
https://forums.phpfreaks.com/topic/107198-mulitple-conditions-in-if-statement/
Share on other sites

if (filetype isn't mp3 or filetype isn't MP3)

 

Apart from anything else, that would ALWAYS run the block. You may aswell just run the if block.

 

I'm finding it hard to put this into words, it's an odd idea, but you're basically saying

if ((number is not one) OR (number is not 2)) do this

 

If we input 1

if ((number is not one FALSE) or (number is not two TRUE)) do this

input 2

if ((number is not one TRUE) or (number is not two FALSE)) do this

input anything apart from one or two

if ((number is not one TRUE) or (number is not two TRUE)) do this

 

whatever you do, you're saying

if TRUE or FALSE = TRUE do this

if FALSE or TRUE = TRUE do this

if TRUE or TRUE = TRUE do this

 

Your if statement cannot return false, so the block will always return true.

 

I think you actually want

 

$filetype = strtolower($filetype);
if($filetype == ".mp3")
{
#Do this if it IS an mp3
}
else
{
#Do this if it IS NOT an mp3
}

 

I hope this clarifies :)

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.