PDA

View Full Version : Checking if a number is either X, Y, or Z


Chen
05 Mar 2002, 18:46
Frequently, you want parts of your hack to only be accessible by moderators and admins.

To do so, you use this if-block:


Code:
---------------
Code is only visible to licensed users, and only when logged into the forums.
---------------


And if you want to give another usergroup access for that action, you need to add even another OR to that statement!

A much more elegant solution would be to use in_array():


Code:
---------------
Code is only visible to licensed users, and only when logged into the forums.
---------------


You can even declare an array, let's say $allowedgroups, that can be used throughout the code:


Code:
---------------
Code is only visible to licensed users, and only when logged into the forums.
---------------



This is also not only useable when checking usergroups! Let's say you have feature you only want visible on forums 4, 6, 18 and 65:


Code:
---------------
Code is only visible to licensed users, and only when logged into the forums.
---------------



Not really a tip nor a trick, but I'm a bit bored so... :)

Neo
06 Mar 2002, 04:55
Very nice firefly. This is very helpful... I really didnt like arrays but I am starting to see the usfulness in them. :D

Dark_Wizard
07 Mar 2002, 19:20
Great info Firefly...very much appreciated, thank you! Can someone post something about joins? I am trying to something using joins and it just isn't working right.

Chen
07 Mar 2002, 19:32
Post in the PHP forum about it and I'll see what I can do. :)

buro9
21 Mar 2002, 07:23
Firefly, that's good, but for performance you should really use a switch as this would prevent the test of an array, convert to an array and loop through array stuff that happens partly implicitly...

try something like...



Code:
---------------
Code is only visible to licensed users, and only when logged into the forums.
---------------



Just an improvement. Doesn't change functionality... but under strain this should shine.