Re: [PHP] If Statement with more than one conclusion
Switch statements work well for these situations as well. They might be faster than checking for the item in a list from an array since an array must be created and searched through. General programming tip: your method *definitely* wouldn't work. The or operator has precendence over the == operator, causing those clauses to be broken up like this: $ext==com net org info Only one of those statements needs to be evaluated to true for the contents of the if statement to be evaluated. The first one will only be true if that's what's inside $ext. The others will always evaluate to true since a string of anything is considered true as a boolean. As a switch: If($ext==comornetororgorinfo){ Then do this } switch($ext) { case com: case net: case org: case info: // then do this break; } Your friendly PHP manual will give you more information on the use of switches. They're useful for more than just this kind of situation (namely when you want to process many possible inputs for one variable). -Adam -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
RE: [PHP] If Statement with more than one conclusion
something like: If(in_array($ext, array(com, net, org, info)){ //Then do this } If(in_array($ext, com.uk, me.uk, org.uk)){ //Then do this } maybe?? -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]] Sent: Thursday, January 03, 2002 4:22 PM To: php-general Subject: [PHP] If Statement with more than one conclusion How can I do an if statement with more than one conclusions Something like this I know this is not correct just an example of what I what to do If($ext==comornetororgorinfo){ Then do this } If($ext==com.ukorme.ukororg.uk){ Then do this } -- Best regards, rdkurth mailto:[EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]