kyleldi Posted April 10, 2009 Share Posted April 10, 2009 Is it possible to use ISSET for two variables? What i've got is a page that says if one url variable exists it does one thing, while if that previous variable and another exists, it does something else. All I really know is that I can check for that variable with code such as if isset($_GET['category'])){ but I'd like to get 'category' and 'sub' I hope i'm making sense, Link to comment https://forums.phpfreaks.com/topic/153518-solved-using-isset-to-get-to-variables/ Share on other sites More sharing options...
mrMarcus Posted April 10, 2009 Share Posted April 10, 2009 if (isset ($var1)) { //do something; } elseif (isset($var1) && isset ($var2)) { //do something else; } && = and || = or you can simply use and or or in place of the symbols .. i've just always used the symbols (sorry, can't remember what they're called). Link to comment https://forums.phpfreaks.com/topic/153518-solved-using-isset-to-get-to-variables/#findComment-806608 Share on other sites More sharing options...
laffin Posted April 10, 2009 Share Posted April 10, 2009 u can use a nested if statement or have an elseif the elseif statement first if isset($_GET['category']) && isset($_GET['subcategory'])){ // blah blah } elseif isset(_$GET['category']) { // blah blah } else { // blah blah } Look as to why we have category and subcategory and understand why we have it above just plain category. but in this instance, i wud prolly nest my ifs instead if isset($_GET['category'])) if(isset($_GET['subcategory'])){ // blah blah } else { // blah blah } } else { // blah blah } Have fun Note that MrMarcus' code will fail the second if statement, as I stated its a pitfall, and never execute the 2nd if statement. Link to comment https://forums.phpfreaks.com/topic/153518-solved-using-isset-to-get-to-variables/#findComment-806609 Share on other sites More sharing options...
ToonMariner Posted April 10, 2009 Share Posted April 10, 2009 you can put multiple vars inside the isset construct... if(isset($foo,$bar,$x)) { ...yourcode if they are all set } Link to comment https://forums.phpfreaks.com/topic/153518-solved-using-isset-to-get-to-variables/#findComment-806613 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.