CalcBuilder Forum

Codes for retrieving group information of logged in users

User adk 2018-11-11 19:55:11

In your tutorial you mention the next code.

$usergroups= $user->groups; // List of Joomla groups this user belongs to (is an array)

Can you help me with the right code to retrieve or recover the data of this array of the list of groups the user belongs to.

We have assigned our customers who have registered on our site to different groups like customergroup1, customergroup2 .. ectera. Each customergroup has a different discount percentage. I am looking for the right code to find out to which group the logged-in user belongs to after the code $usergroups= $user->groups; and give him/her a certain discountpercentage when he/she uses our calculator.

Which PHP code do I have to use? Do I need column or row names? And if yes how to find these names in the array.

Best regards

Moonsoft support 2018-11-12 10:01:30

that specific code will give you a collection of identifiers of the groups the actual user belongs to. So you will have at


, the group number of the first group assigned, at $usergroups
the id number of the second group assigned, etc.
You can check if the user belongs, for ex, to group 8, using in_array function

//the user belongs to group 8

you could also loop through all array values using for/foreach expressions

foreach($usergroup as $group){

//code here for the group id $group

Hope this helps, regards


Create dynamic calculators

Buy now!
Support/development 10 hours

Get a bigger amount of hours for more complex tasks and get a 10% discount

Buy now!