Darkmatter5 Posted July 29, 2008 Share Posted July 29, 2008 Can I shorten this code if($field=="survey_id_1" || $field=="survey_id_2" || $field=="survey_id_3) to something like this? if($field=="survey_id_1" || "survey_id_2" || "survey_id_3) Link to comment https://forums.phpfreaks.com/topic/117195-multiple-comparisons-in-if-statement-syntax-help/ Share on other sites More sharing options...
d.shankar Posted July 29, 2008 Share Posted July 29, 2008 Can survey_id_1,survey_id_2,survey_id_3 etc can be kept in an array ? Link to comment https://forums.phpfreaks.com/topic/117195-multiple-comparisons-in-if-statement-syntax-help/#findComment-602830 Share on other sites More sharing options...
obsidian Posted July 29, 2008 Share Posted July 29, 2008 Can survey_id_1,survey_id_2,survey_id_3 etc can be kept in an array ? As d.shankar suggests, you could do this: <?php if (in_array($field, array('survey_id_1', 'survey_id_2', 'survey_id_3')) { } ?> In this case, though, that's not much of an improvement on length, unless you can build the comparative array dynamically in your code. Also, using your if clause is probably much faster than trying to use another function call for the comparison. Link to comment https://forums.phpfreaks.com/topic/117195-multiple-comparisons-in-if-statement-syntax-help/#findComment-602837 Share on other sites More sharing options...
d.shankar Posted July 29, 2008 Share Posted July 29, 2008 Obsidian is an advanced geek !!! Link to comment https://forums.phpfreaks.com/topic/117195-multiple-comparisons-in-if-statement-syntax-help/#findComment-602841 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.