Darkwoods Posted February 16, 2010 Share Posted February 16, 2010 im trying to have different values but i don't know how to separate them, i tried with , . 'AND' but still not working with me i googeled it but could not find any examples thanks <?php if($var == 'value1' or 'value2' or 'value3') { echo 'Lets echo it!'; } ?> Link to comment https://forums.phpfreaks.com/topic/192232-how-can-i-have-more-than-one-value-in-a-variable/ Share on other sites More sharing options...
jl5501 Posted February 16, 2010 Share Posted February 16, 2010 if($var == 'value1' or $var == 'value2' or $var == 'value3') or if($var == 'value1' || $var == 'value2' || $var == 'value3') Link to comment https://forums.phpfreaks.com/topic/192232-how-can-i-have-more-than-one-value-in-a-variable/#findComment-1013009 Share on other sites More sharing options...
Darkwoods Posted February 16, 2010 Author Share Posted February 16, 2010 ah thanks it worked just one question u cant seperate the values somethin like that $var == 'value1', 'value2', 'value3', etc in PHP? anyway thanks Link to comment https://forums.phpfreaks.com/topic/192232-how-can-i-have-more-than-one-value-in-a-variable/#findComment-1013011 Share on other sites More sharing options...
jl5501 Posted February 16, 2010 Share Posted February 16, 2010 no, you have to give the 2 sides of the comparison each time Link to comment https://forums.phpfreaks.com/topic/192232-how-can-i-have-more-than-one-value-in-a-variable/#findComment-1013022 Share on other sites More sharing options...
Thierry Posted February 16, 2010 Share Posted February 16, 2010 There's always the option to use an array and check with in_array or something like that. Don't know about performance and such though. if(in_array($var,array("value1","value2","value3)) { } Link to comment https://forums.phpfreaks.com/topic/192232-how-can-i-have-more-than-one-value-in-a-variable/#findComment-1013028 Share on other sites More sharing options...
Darkwoods Posted February 16, 2010 Author Share Posted February 16, 2010 thanks Link to comment https://forums.phpfreaks.com/topic/192232-how-can-i-have-more-than-one-value-in-a-variable/#findComment-1013031 Share on other sites More sharing options...
berridgeab Posted February 16, 2010 Share Posted February 16, 2010 switch statement too : Link to comment https://forums.phpfreaks.com/topic/192232-how-can-i-have-more-than-one-value-in-a-variable/#findComment-1013083 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.