Jump to content

Recommended Posts

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';
            }
Link to comment
https://forums.phpfreaks.com/topic/300615-in-array-logic/
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/300615-in-array-logic/#findComment-1530227
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.