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.