Jump to content

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 :)

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.