lilmer Posted January 22, 2016 Share Posted January 22, 2016 Is there a better way to do this? $p = 3; $a = 3; $b = 3; $arr = [$p,$a,$b]; if (in_array(0, $arr)) { return 'Pending'; } if ((in_array(2, $arr)) && !in_array(0, $arr)) { return 'Incomplete'; } if ((in_array(1, $arr)) && !in_array(0, $arr) && !in_array(1, $arr)) { return 'Approved'; } if (in_array(3, $arr) && !in_array(0, $arr) && !in_array(1, $arr) && !in_array(2, $arr)) { return 'Declined'; } Quote Link to comment Share on other sites More sharing options...
cyberRobot Posted January 22, 2016 Share Posted January 22, 2016 Have you considered using elseif? More information can be found here: http://php.net/manual/en/control-structures.elseif.php If that doesn't work, it might help if you provide more information on what you're trying to accomplish. Quote Link to comment Share on other sites More sharing options...
lilmer Posted January 22, 2016 Author Share Posted January 22, 2016 Yes Sir elseif, but on logic of getting `Pending`, `Incomplete` etc.. base on the array, is there other way? Quote Link to comment Share on other sites More sharing options...
cyberRobot Posted January 22, 2016 Share Posted January 22, 2016 Just to clarify, do you want the script to output one result (Pending, Incomplete, etc.)? If so, I think in_array() and elseif should work fine. But I'm sure there are other ways. It depends on what you are trying to do and what you are doing with the rest of the code. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.