scott212 Posted January 15, 2007 Share Posted January 15, 2007 is there any way to evaluate multiple values in an 'if' condition? Example: if ($value != 1,2,3,4) or if ($value == 1||2||3||4||)Do you know of anything like this? I can't seem to find anything on google. Sure would clean up some code Link to comment https://forums.phpfreaks.com/topic/34294-evaluate-multiple-conditions/ Share on other sites More sharing options...
owenjh Posted January 15, 2007 Share Posted January 15, 2007 You can evaluate multiple conditions by doing the following:if ($var == 1 || $var == 2 || $var == 3) {} Link to comment https://forums.phpfreaks.com/topic/34294-evaluate-multiple-conditions/#findComment-161311 Share on other sites More sharing options...
Orio Posted January 15, 2007 Share Posted January 15, 2007 There are few ways doing it... Here are two I can think of:[code]<?php//first way, the regular wayif($value == 1 || $value == 2 || $value == 3 || $value == 4)//second way, using an array and in_array()if(in_array($value, array(1,2,3,4)))?>[/code]Orio. Link to comment https://forums.phpfreaks.com/topic/34294-evaluate-multiple-conditions/#findComment-161313 Share on other sites More sharing options...
scott212 Posted January 15, 2007 Author Share Posted January 15, 2007 wow - I can't believe how quick to respond this community is. You suggestions are great, thank you! (I think I like the regular way for clarity reasons) Link to comment https://forums.phpfreaks.com/topic/34294-evaluate-multiple-conditions/#findComment-161317 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.