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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T03:33:42+00:00 2026-05-26T03:33:42+00:00

I have two questions. Both involve CodeIgniter’s session support when using the database as

  • 0

I have two questions. Both involve CodeIgniter’s session support when using the database as a backend.

1. I’m wondering if there is a way of unsetting an inner element of an array against a session when using CodeIgniter’s Database Session support.

For example, in standard PHP this sort of functionality is possible:

unset($_SESSION['items'][$item_name]);

However, CodeIgniter seems to work like this:

$this->session->unset_userdata('items'); // What about unsetting $item_name specifically?

2. And I’m not sure the best way of unsetting an individual array item.

The other thing I would like to be able to do is to check whether an inner element of an array is set.

For example, in standard PHP this sort of functionality is possible:

if (isset($_SESSION['items'][$item_name])) {
}

But in CodeIgniter we have something like this:

if ($this->session->userdata('items') !== FALSE) {
}
  • 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-26T03:33:43+00:00Added an answer on May 26, 2026 at 3:33 am

    The equivalent to $_SESSION in Codeigniter is

    $this->session->userdata
    

    This might look like the same named function name

    $this->session->userdata();
    

    to you, but in fact it’s an array, like $_SESSION. With this information, let’s look at your specific questions:

    # 1. unset an item:
    unset($this->session->userdata['items'][$item_name]);
    
    # 2. check if an item is set:
    if (isset($this->session->userdata['items'][$item_name])) {
    }
    

    If you would like to access that more easily, you can create a reference/alias:

    $session =& $this->session->userdata;
    
    unset($session['items'][$item_name];
    
    if (isset($session['items'][$item_name])) {
    }
    

    To apply the changes to the session variable(s), you need to call

    $this->session->sess_write();
    

    to store the values into the database. That’s better than using the userdata() function, because it will trigger a write in the database whenever you set a single value.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two questions, both related to the same view: so there is view
I have two questions. 1) Should you always use a using statement on a
I have two different questions(on both questions need to ignore spaces) How to print
I actually have two questions, both are probably simple, but for some odd reason
I have two questions regarding RewriteRule, but they're both closely related so I hope
I actually have two questions today, but they are both small :-) 1) Where
I have two questions.They both are concerning a void in C++,which I am trying
I have two questions regarding binary search trees, both about empty trees. Is an
I have two Pages A and B. Both should display a Text using the
I have two questions: 1) How can I make an array which points to

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.