Dragonfly CMS v9 ⇒ Modules & Blocks :: Archives ⇒ in_array($group_id, $userinfo['_mem_of_groups']) not working :: Archived ⇒ Community Forums ⇒ CPG Dragonfly™ CMS
Forum IndexModules & Blocks

Archived ⇒ in_array($group_id, $userinfo['_mem_of_groups']) not working


Hi.
I'm making a module and need some help here.

For example I want to check if user is in specified use group, I would use this code:
$group_id = 3; if (in_array($group_id, $userinfo['_mem_of_groups'])) { echo 'Yep, your\'e in Group with ID '.$group_id; }

But it does NOT work Rolling Eyes
I found an uglier way to do it though:
$group_id = 3; $view = array(); foreach($userinfo['_mem_of_groups'] AS $key => $value) { $view[] = $key; } if (in_array($group_id, $view)) { echo 'Yep, your\'e in Group with ID '.$group_id; }

Why do I need to make a new array, if $userinfo['_mem_of_groups'] is already an array?



To test it make a new module with content(change group_id to one where you certainly belong):
<?php if (!defined('CPG_NUKE')) { exit; } $pagetitle = 'Tests'; require_once('header.php'); $group_id = 3; OpenTable(); /********* TEST 1 **********/ if (in_array($group_id, $userinfo['_mem_of_groups'])) { echo 'Test 1: Yep, your\'e in Group with ID '.$group_id; } /********* TEST 2 **********/ $view = array(); foreach($userinfo['_mem_of_groups'] AS $key => $value) { $view[] = $key; } if (in_array($group_id, $view)) { echo 'Test 2: Yep, your\'e in Group with ID '.$group_id; } CloseTable();
Any help is appreciated, thanks!

Server specs (Server OS / Apache / MySQL / PHP / DragonflyCMS):
-


php.net/in_array
php.net/array_key_exists
php.net/isset
php.net/empty
php.net/print_r

.:: I met php the 03 December 2003 :: Unforgettable day! ::.

Server specs (Server OS / Apache / MySQL / PHP / DragonflyCMS):
CloudLinux / Apache 2.4 LSAPI / MySQLi 5.7 / PHP 7.3 / head


Thanks Nano, print_r showed me what's wrong, I wouldn't have thought that group name would also be kept in array.

I'll try to fix my code then...
EDIT: Yes, array_key_exists did the work perfectly, thanks again.

EDIT2: Bah, I could have just use Dragonfly´s function in_group()

Server specs (Server OS / Apache / MySQL / PHP / DragonflyCMS):
-

All times are UTC