I have the following arrays below in PHP that I store a user_id number in to keep track of moderator/admins on my site, then in a page I can just use in_array() to determine if a user should have moderator privileges, I figure this saves some mysql queries by using an array instead.
I am wondering, would there be any performance gain from combining these into 1 bigger array instead of seperate ones?
If so could you show an example how I can combine them and use it?
Maybe list some reasons for 1 way over the other?
$moderators = array(1,99,88,77,2,3,4,5);
$bulletin_moderators = array(1,1091,13,103);
$forum_moderators = array(1,1091,34850,13,103,21);
$blog_moderators = array(1,1091,21);
$photo_moderators = array(1,1091,13,34850,103,21);
$chat_moderators = array(1,44534);
Performance gain? No. Maintainability gain? Definitely. Try this:
As the above poster said though, these really shouldn’t be hardcoded. A DB query wouldn’t take any significant amount of time, and it would probably be cached in memory or in the database itself (assuming you use mysql).
What if you add more users? You would have to edit your source. What if you had multiple servers? You would have to edit your source on X amount of servers.