jonniejoejonson Posted April 29, 2010 Share Posted April 29, 2010 Is there a shorter way to write... if($name=='dave'||$name=='thomas'||$name=='steve'){ } Link to comment https://forums.phpfreaks.com/topic/200142-is-there-a-shorter-way-to-write/ Share on other sites More sharing options...
ignace Posted April 29, 2010 Share Posted April 29, 2010 if (in_array($name, array('dave','thomas','steve')) shorter but I doubt it's faster Link to comment https://forums.phpfreaks.com/topic/200142-is-there-a-shorter-way-to-write/#findComment-1050406 Share on other sites More sharing options...
jonniejoejonson Posted April 29, 2010 Author Share Posted April 29, 2010 Thanks ignance, I thught you might be able to write something like: if($name==('dave'||'thomas'||'steve')){ } but apparently not. Link to comment https://forums.phpfreaks.com/topic/200142-is-there-a-shorter-way-to-write/#findComment-1050408 Share on other sites More sharing options...
JAY6390 Posted April 29, 2010 Share Posted April 29, 2010 Nope that's as good as it gets jonnie Link to comment https://forums.phpfreaks.com/topic/200142-is-there-a-shorter-way-to-write/#findComment-1050418 Share on other sites More sharing options...
Roopa Lakhlani Posted April 29, 2010 Share Posted April 29, 2010 $name_list = array('dave','thomas','steve); $read_name = 'steve'; if (in_array($read_name,$name_list) { echo "hello" .$read_name; } Link to comment https://forums.phpfreaks.com/topic/200142-is-there-a-shorter-way-to-write/#findComment-1050431 Share on other sites More sharing options...
jonniejoejonson Posted April 29, 2010 Author Share Posted April 29, 2010 Thanks guys. Link to comment https://forums.phpfreaks.com/topic/200142-is-there-a-shorter-way-to-write/#findComment-1050433 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.