vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB3 Programming Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=15)
-   -   syntax problems with checking for constants in an array? (https://vborg.vbsupport.ru/showthread.php?t=148934)

saf-t scissors 06-05-2007 01:47 AM

syntax problems with checking for constants in an array?
 
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.

Quote:

Originally Posted by Dream (Post 1261588)

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

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

Dismounted 06-06-2007 09:44 AM

Code:

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

PHP Code:

if (is_member_of($userUSERGROUPA)) 

Which will check primary & secondary usergroups for USERGROUP_A.

Dismounted 06-07-2007 07:40 AM

Quote:

Originally Posted by Dream (Post 1262898)
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.
Code:

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?
PHP Code:

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().


All times are GMT. The time now is 11:48 AM.

Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.

X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.00984 seconds
  • Memory Usage 1,737KB
  • Queries Executed 10 (?)
More Information
Template Usage:
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (2)bbcode_code_printable
  • (2)bbcode_php_printable
  • (2)bbcode_quote_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (1)pagenav_pagelink
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (10)printthreadbit
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • showthread
Included Files:
  • ./printthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/class_bbcode_alt.php
  • ./includes/class_bbcode.php
  • ./includes/functions_bigthree.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • printthread_start
  • pagenav_page
  • pagenav_complete
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete