The Arcive of Official vBulletin Modifications Site.It is not a VB3 engine, just a parsed copy! |
|
#1
|
|||
|
|||
Array not working?
why does this array not work?
I am ok getting around PHP, just not 100% PHP Code:
|
#2
|
|||
|
|||
That doesn't work because what you're doing is comparing an integer ($vbulletin->userinfo['usergroupid']) to an array, which doesn't do what you're expecting. There's a php function called in_array() that does what you want:
PHP Code:
There's also a vbulletin function called is_member_of() that you can use: PHP Code:
that will also check the secondary usergroups (which may or may not be what you want, but unless you have some very complicated usergroup system, it probably does what you want). |
#3
|
|||
|
|||
Quote:
I actually made it work with AND, well i think it worked ? I have not asked the moderators to test the script yet???? PHP Code:
|
#4
|
|||
|
|||
That would work for checking 6 but not 7. What you'd want is this: PHP Code:
Oh, and in my post above I forgot that you were checking for !=, so you'd of course want to use !in_array() and !is_memebr_of(). |
#5
|
|||
|
|||
Quote:
I really wanted to like your post lol, but it wont let me because i liked a post of yours 6 months ago. Also just out of curiosity why does this work PHP Code:
PHP Code:
|
#6
|
|||
|
|||
When you use 'AND', then the expression is true only if the expressions on both sides of AND are true. In this code:
Code:
if ($vbulletin->userinfo['usergroupid'] != 6 AND 7) PHP Code:
I hope that makes sense. Or maybe a better way to put it would be that the != has higher precedence than AND, so if you were to put parens in the expression to make it clear, what you'd have is this: PHP Code:
|
#7
|
|||
|
|||
So the AND does not look at the code as
usergroup 6 and usergroup 7 it looks at it like usergroup 6 and 7 because the 6 is on the left of the AND, would that also be true with OR Thanks KH99 |
#9
|
|||
|
|||
Quote:
But I should also point out (just to make it more confusing) that even if AND were higher so that the expression 6 AND 7 were evaluated first, it still doesn't do what you'd want, so in a way I guess this is an overly complicated answer to your question. I suppose it's just that sometimes if you read the code like it's English it means something different than it does in php, so $x != 6 AND 7 might make sense in English, but it's not correct php (or at least it's not correct for what you're trying to do). Live Dave says, it's usually easier to use in_array(), although I feel that if you only have 2 values then ANDing 2 checks is not so bad. But I'm not an expert php programmer, escpecially when it comes to style. Oh, and yeah, OR would be the same. |
#10
|
|||
|
|||
Thank you it does make allot of sense...
I am quite good at building smaller scripts and making things work, but I am trying to build a large-ish plugin for my community but it seems a bit challenging with my knowledge. However I think to improve my skills I need to have a go Again thanks KH99 I really appreciate the explanation and your time. Mick |
Благодарность от: | ||
MarkFL |
Thread Tools | |
Display Modes | |
|
|
X vBulletin 3.8.12 by vBS Debug Information | |
---|---|
|
|
More Information | |
Template Usage:
Phrase Groups Available:
|
Included Files:
Hooks Called:
|