If Statement with grouped conditions

I have an array with various keys and values that are properties from a pipe delimited data file. I need to exclude certain users based on if a user (an array within a “data” array) has two specific properties set to two specific values as well as a 3rd value not being set to null. Example:
if ($properties[‘value3’] != null && !($properties[‘value1’] && $properties[‘value2’]))

This statement removes all users that have value3 null and all value1 and all value2, but I want users to only be exclude when a single user has both value1 and value2 set. I still need users that have one or the other values to be included. What am I missing in my logic?

Your needs:
— Remove if value3 null
— Keep if value3 not null AND— either value1 or value2

So…

if ( $properties[‘value3’] != null AND ( $properties[‘value1’] != null OR $properties[‘value2’] != null ) )
if I understand you correctly…

if ( $properties[‘ID’] != null AND !( $properties[‘Department’] == ‘Academic Affairs’ AND $properties[‘Person Type’] == ‘Affiliate’ ) )
I only want to exclude a user that has BOTH Department == ‘Academic Affairs’ AND Person Type’ == ‘Affiliate’ as well as their ‘ID’ not being null. So, you’re answer is close to what I need. I will run it and see.

That only selects users that HAVE the Person Type of ‘Affiliate’ or Department of ‘Academic Affairs’. It needs to allow all other Person Types and Departments. No there yet.

So, your needs:
— ID is not null
— depart = AA
— type = aff

Just remove the parens…
if ( $properties[‘ID’] != null AND $properties[‘Department’] == ‘Academic Affairs’ AND $properties[‘Person Type’] == ‘Affiliate’ )

You can use the && / !! as needed, but, I like to use AND / OR as it is much easier to read.

Sorry for any confusion, but it has to exclude any user that has BOTH depart = AA and type = aff, but allow users with one or the other to pass.

So, your needs:
— ID is not null
— depart = AA
— type = aff

Just remove the parens…
if ( $properties[‘ID’] != null AND $properties[‘Department’] == ‘Academic Affairs’ AND $properties[‘Person Type’] == ‘Affiliate’ )

You can use the && / !! as needed, but, I like to use AND / OR as it is much easier to read.

Is this to define logic flow or something else?

I am a big proponent of using classes and role based allowance.

So, what are you trying to determine based on these results?

Ultimately it is a filter to weed out certain users from an array that will be converted to JSON that will be used by an Angular Controller to render a searchable directory.
As stated in an earlier post of mine, “exclude any user that has BOTH depart = AA and type = aff, but allow users with one or the other (values, ‘Academic Affairs’ or ‘Affiliate’) to pass.”

Does that mean, it’s coming out of a database initially?

I figured out why it wasn’t working as I expected Visual Studio Code’s intellisence suggested a variable that was not correct and I selected it assuming it was the one I had assigned to ‘Department’. I could kick myself for missing this stupid mistake! Sorry to waste your time. Ultimately this was all I needed:

if ($ID != null && !($personType == “Affiliate” && $userDept == ‘Academic Affairs’))

Thanks!

Glad you found a solution. However, if it is coming out of a database, you could make it even easier.

It is coming from a database, but I only have access to an attribute file that it outputs nightly.

Sponsor our Newsletter | Privacy Policy | Terms of Service