PDA

View Full Version : syntax problems with checking for constants in an array?


saf-t scissors
06-05-2007, 01:47 AM
if ($user[membergroupids] == USERGROUP_A) always returns true, but
if ($user[membergroupids] == 'USERGROUP_A') and
if ($user[membergroupids] == " . USERGROUP_A . ") always returns false

If I just go
if ($user[membergroupids] == '2'), it works as it should.

Similarly, later on,

if ($groupid != USERGROUP_A) branches properly.

WTF am I doing wrong?

Code Monkey
06-05-2007, 01:59 AM
Have you tried $user['membergroupids'] ?

saf-t scissors
06-05-2007, 02:31 AM
That doesn't seem to affect it.

Thanks, though.

Dream
06-05-2007, 06:33 AM
$user[membergroupids] is a list of user groups separated by commas

you need to explode(',') it and get an array with a list of user group ids to work with

not sure if constants get parsed inside quotes, but this

if ($user[membergroupids] == " . USERGROUP_A . ")

should work I think O_o

saf-t scissors
06-05-2007, 09:03 PM
Correct. I was actually trying to check for one (and only one) membergroup. If there were more than one, it branched and did something else.



if ($user[membergroupids] == " . USERGROUP_A . ")


That always returns as false. I'm not sure why.

Dismounted
06-06-2007, 09:44 AM
if ($user[membergroupids] == " . USERGROUP_A . ")
There is no need to concencate the constant....You're not including any other bits of data.

Dream
06-07-2007, 03:13 AM
still he's curious, as am I

Adrian Schneider
06-07-2007, 03:21 AM
if (is_member_of($user, USERGROUPA))Which will check primary & secondary usergroups for USERGROUP_A.

Dismounted
06-07-2007, 07:40 AM
still he's curious, as am I
Are you referring to my post? If you are, you're not starting the string, so it'd error out.
if ($user[membergroupids] == "" . USERGROUP_A . "")
That would work.

Adrian Schneider
06-07-2007, 07:06 PM
Why even add the empty strings around it though? if ($user['membergroupids'] == USERGROUP_A) is correct, but membergroupids is a comma separated list, so you need to either explode it, or use is_member_of().

Dream
06-07-2007, 08:02 PM
Oh I thought those were double single quotes, not double quotes, my bad :P

Dismounted
06-08-2007, 10:17 AM
Why even add the empty strings around it though?
Read the thread?