Log in

View Full Version : Using if (in_array with $vboptions?


Deaths
02-18-2005, 06:32 PM
In a PHP file, I try the following condition:

if (in_array($bbuserinfo[usergroupid], array($vboptions['vbma_pmember'])))
{

But it just doesn't parse the $vboptions variable...

Help would be appreciated.

deathemperor
02-19-2005, 02:49 AM
then depending what is that $vboptions['vbma_pmember'], is it an array ? I don't think it can be an array, if you want something like this:

$vboptions['vbma_pmember'] store the value of "1,2,4,5,7" then you must first explode() it so that it can be an array, then in the function in_array() it'll surely work. The "," can be " " or any special character.

Deaths
02-19-2005, 09:09 AM
The vbma_pmember is a basic ACP setting, with 6,11,9 in it.

Anyway, I'll look into it a bit closer, I'll let you know if I still can't get it to work.

deathemperor
02-19-2005, 09:12 AM
if it's 6,11,9 then follow the way I posted it sure works

Deaths
02-19-2005, 09:17 AM
If I use the explode() feature, will I still be able to get the data from the $vboptions variable?

Could you post a little example code maybe :).
It's my first hack public hack, so I'm not used to using variables...

deathemperor
02-19-2005, 03:22 PM
explode() doesn't eat any of your data. I won't suggest it if it can't get the data from $vboptions varible, absolutely. Of course if the data is entered correctly like if you use explode(',',$vboptions['something']) but you then will have to give some exceptions when someone suddenly enter 1,2-3,4 which returns unexpected value.

I regard the above is an example. if you don't know explode(), php.net then

Deaths
02-19-2005, 03:48 PM
Thanks for the reply.

I tried this and it didn't work:

$pmembers = $vboptions['vbma_pmember'];
$pusergroups = explode(",", $pmembers);
if (!in_array($bbuserinfo['usergroupid'], array($pusergroups)))
{


Now it just displays the page for everyone...

EDIT:
FIXED

Marco van Herwaarden
02-19-2005, 06:04 PM
Leave out the array( ..) around $pusergroups

Deaths
02-19-2005, 06:06 PM
Yes, that's how I fixed it :).

Little late, but thanks for the reply.