Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3443422
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T08:47:21+00:00 2026-05-18T08:47:21+00:00

Ok, I am wanting to do something like this: $which = !empty($param_id) ? [‘groups’][$param_id]

  • 0

Ok, I am wanting to do something like this:

$which = !empty($param_id) ? "['groups'][$param_id]" : "['groups']";

And than I’d like it to be able to do something like so…

$all_groups . $which = array(
    -1 => array(
    'id' => '-1',
    'name' => $txt['parent_guests_only'],
    'checked' => in_array('-1', $checked) || in_array('-3', $checked),
    'is_post_group' => false,
)

And I need it to build an array like so, if !empty($param_id)

$all_groups['groups'][$param_id] = array(the array info);

But if $param_id is empty it should do the this instead:

$all_groups['groups'] = array(the array info);

I don’t think I can concatenate it or can I?

Can someone please help me here? This is happening many many times throughout a function, so I don’t want to use if… else… statements every single time. Would be too many, thinking of a 1 fast approach for all of them.

Thanks 🙂

EDIT, here is the function in question:

function ListGroups($checked = array(), $unallowed = array(), $order = array(), $param_id = 0)
{
    global $context, $smcFunc, $txt;

    // We'll need this for loading up the names of each group.
    if (!loadLanguage('ManageBoards'))
        loadLanguage('ManageBoards');

    if (empty($checked))
        return array();

    $all_groups['groups'][$param_id] = array();

    if (!in_array('-1', $unallowed))
        // Guests
        $all_groups['groups'][$param_id] = array(
            -1 => array(
                'id' => '-1',
                'name' => $txt['parent_guests_only'],
                'checked' => in_array('-1', $checked) || in_array('-3', $checked),
                'is_post_group' => false,
            )
        );

    if (!in_array('0', $unallowed))
    {
        // Regular Members
        if (!empty($all_groups['groups']))
            $all_groups['groups'][$param_id] += array(
                0 => array(
                    'id' => '0',
                    'name' => $txt['parent_members_only'],
                    'checked' => in_array('0', $checked) || in_array('-3', $checked),
                    'is_post_group' => false,
                )
            );
        else
            $all_groups['groups'][$param_id] = array(
                0 => array(
                    'id' => '0',
                    'name' => $txt['parent_members_only'],
                    'checked' => in_array('0', $checked) || in_array('-3', $checked),
                    'is_post_group' => false,
                )
            );
    }

    // Load membergroups.
    $request = $smcFunc['db_query']('', '
        SELECT group_name, id_group, min_posts
        FROM {db_prefix}membergroups
        WHERE id_group > {int:is_zero}',
        array(
            'is_zero' => 0,
        )
    );
    while ($row = $smcFunc['db_fetch_assoc']($request))
    {
        if (!in_array($row['id_group'], $unallowed))
        {
            $all_groups['groups'][(int) $param_id][(int) $row['id_group']] = array(
                'id' => $row['id_group'],
                'name' => trim($row['group_name']),
                'checked' => in_array($row['id_group'], $checked) || in_array('-3', $checked),
                'is_post_group' => $row['min_posts'] != -1,
            );
        }
    }
    $smcFunc['db_free_result']($request);

    // Let's sort these arrays accordingly!
    if (!empty($order))
    {
        $all_groups['groups'][$param_id] = sortGroups($all_groups['groups'][$param_id], $order);
        $context['group_order' . $param_id] = implode(', ', $order);
    }
    else
    {
        $context['group_order' . $param_id] = '';
        sort($all_groups['groups'][$param_id]);
        $x = 0;
        foreach ($all_groups['groups'][$param_id] as $key => $value)
        {
            $x++;
            $context['group_order' . $param_id] .= $x < count($all_groups['groups'][$param_id]) ? $value['id'] . ', ' : $value['id'];
        }
    }

    return $all_groups['groups'][$param_id];
}

I need to do a check for !empty($param_id), if so, it needs to build the $all_groups[‘groups’] array without the $param_id.

So will need to add in a check for if (!empty($params_id)) build the array like so: $all_groups['groups'][$params_id] else build it like this instead: $all_groups['groups']. I don’t want a bunch of if… else… statements in here, just a 1 or 5 liner would be GREAT!

Thanks Guys 🙂

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T08:47:22+00:00Added an answer on May 18, 2026 at 8:47 am

    Don’t overcomplicate it. 🙂

    $array = array(
        /* contents */
    );
    
    if (!empty($param_id)) {
        $all_groups['groups'][$param_id] = $array;
    } else {
        $all_groups['groups'] = $array;
    }
    

    I don’t know what $all_groups['groups'] looks like before this; if it was empty, I’d shorten this to:

    $all_groups['groups'] = array(
        /* contents */
    );
    
    if (!empty($param_id)) {
        $all_groups['groups'] = array($param_id => $all_groups['groups']);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a workflow that I want to looks something like this: / Worker
I want to do something like this: Create a number of assemblies that implement
I'm completely new to LaTeX and something I'm wanting to do is eluding me.
I am wanting to access a website from a different port than 80 or
I just been given a new assignment which looks like its going to be
I'm hoping to implement something like all of the great plugins out there for
I have a program that calls a Filewatcher function, like this Main() { watch();
Wanting to implement authentication by client certificates I am experiencing some issues. First some
I wanting to show prices for my products in my online store. I'm currently
Not wanting to re-invent the wheel or anything, I was wondering if there's a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.