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 6857681
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T02:03:27+00:00 2026-05-27T02:03:27+00:00

I have an array that’s made up of data returned by a SQL query:

  • 0

I have an array that’s made up of data returned by a SQL query:

$_SESSION['licensed_users'] = $db->get_results("SELECT np.id FROM `new_people` np LEFT JOIN institute.users_roles ur ON np.institute_uid = ur.uid WHERE np.company_id=$company_id AND ur.rid=8 AND np.active = 1");

This returns an array that looks like this:

Array ( 
   [0] => stdClass Object ( [id] => 25590 )
   [1] => stdClass Object ( [id] => 40657 )
   [2] => stdClass Object ( [id] => 60685 ) 
   [3] => stdClass Object ( [id] => 61900 )
   [4] => stdClass Object ( [id] => 65224 )
   [5] => stdClass Object ( [id] => 65369 ) 
   [6] => stdClass Object ( [id] => 79171 ) 
   [7] => stdClass Object ( [id] => 80763 )
   [8] => stdClass Object ( [id] => 80762 ) 
   [9] => stdClass Object ( [id] => 80761 )
 )

In another section of the code I loop through the values to see if the current user is part of that array:

foreach($_SESSION'licensed_users'] as $key=>$value) {
   if($value->id == $people_id) {
      $is_licensed = true;
   }
}

$is_licensed is used to determine which set of form fields to display to the user. When the user submits the form, if a certain group of fields is set to a certain value, I need to either add the user ($people_id) to the $_SESSION['licensed_users'] array if $is_licensed is false, or remove them from the array if $is_licensed is true. The code for determining which action to take is no problem; I just can’t for the life of me remember/figure out how to add to an array of objects. I’ve seen this and this, but I already know if the ID is in the array or not; I just need to be able to add or remove it.

(Yes, there is a reason we’re using session variables – we need to be able to pass values between pages of the site. It’s either that or cookies.)

I’ve tried $_SESSION['licensed_users'][] = array("id"=>$people_id); but it doesn’t seem to actually do anything.

  • 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-27T02:03:27+00:00Added an answer on May 27, 2026 at 2:03 am

    To remove $lu[6]:

    unset($lu[6]);
    

    To add an element:

    $lu[] = $current_user;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a two dimensional array that I need to load data into. I
I have an array that is structured as such: $data = array( abc=>array( label
I have an array that gets created from JSON. The array looks like this:
I have an array that gets its values from a text file. Each line
I have an array that doesn't use the 0 index. The array starts from
I have an array that contains a list of vertices which I copy to
I have an array that looks like: $fields = array( f1 => array(test), f2
I have an array that has keys and values. For eg: Array ( [name]
I have an array that looks like $numbers = array('first', 'second', 'third'); I want
I have an array that is a member of a structure: $self->{myArray} = [value1,

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.