How to unset specific data array in codeigniter

Its been two days I'm working with these guys. Need help here.

here is my view

$username = json_decode($this->session->userdata('users'), TRUE);

    foreach ($username AS $key => $value) {

    <?php echo $value['username']; ?>
    <?php echo $value['firstname']; ?>
    <?php echo $value['lastname']; ?>
    <?php $u = $value['username']; ?>
    <?php echo "<a href=".base_url()."index.php/bets/un_sess/$u /> X </a> " ?>

    <?php } ?>

here is my controller

$user1 = json_decode($this->session->userdata('users'), TRUE);
 foreach ($user AS $key => $value) {
       $index = array_search($username, $user);
       unset($user[$index]);          
      $this->session->set_userdata('users', $user);

array from user_data

{"username":"user1","firstname":"name1","lastname":"name2"},
{"username":"user2","firstname":"test","lastname":"test"}

the output of this is when the first time i click the username its working but when i click another username it gives error like this

A PHP Error was encountered

Severity: Warning

Message: Illegal offset type in isset or empty

Filename: libraries/Session.php

Line Number: 433 A PHP Error was encountered

Severity: Warning

Message: Invalid argument supplied for foreach()

Filename: controllers/bets.php

Line Number: 290

Answers


ok since there is no answering in my questions. Here is my solutions

 $user = json_decode($this->session->userdata('users'), TRUE);
        foreach ($user AS $key => $value) {
          if ($username == $value['username']){

          unset($user[$key]);
         }
        }

       $this->session->set_userdata('users', json_encode($user));

Need Your Help

Add ETag using IHttpModule

asp.net httpmodule etag

I have wrote a simple IHttpModule

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.