title: in_array not working codeigniter
body: <p>I cannot get my in_array to work on my library both functions are on same library.  I will not let me do </p>
  
  <p><code>$this-&gt;user_auth-&gt;hasPermission('modify', 'folder/controller-name');</code></p>
  
  <p>By using the function above I can check if has permission to modify.</p>
  
  <p>On my library function hasPermission the $key &amp; $value does not work.</p>
  
  <p>On my login function I unserialize the permissions </p>
  
  <p>I cannot figure out why that the hasPermission always returns false.</p>
  
  <p><strong>Login</strong></p>
  
  <pre><code>public function login($username, $password) {
      $user_query = $this-&gt;CI-&gt;db-&gt;query("SELECT * FROM " . $this-&gt;CI-&gt;db-&gt;dbprefix . "user 
          WHERE username = " . $this-&gt;CI-&gt;db-&gt;escape($username) . "
          AND (password = SHA1(CONCAT(salt, SHA1(CONCAT(salt, SHA1(" . $this-&gt;CI-&gt;db-&gt;escape($password) . "))))) 
          OR password = " . $this-&gt;CI-&gt;db-&gt;escape(md5($password)) . ") 
          AND status = '1'
      ");
  
      if ($user_query-&gt;num_rows() &gt; 0) {
  
          $this-&gt;user_id = $user_query-&gt;row('user_id');
          $this-&gt;username = $user_query-&gt;row('username');
          $this-&gt;user_group_id = $user_query-&gt;row('user_group_id');
  
          $data_session = array(
              'logged' =&gt; true,
              'user_id' =&gt; $this-&gt;user_id
          );
  
          $this-&gt;CI-&gt;session-&gt;set_userdata($data_session);
  
          $user_group_query = $this-&gt;CI-&gt;db-&gt;query("SELECT permission FROM " . $this-&gt;CI-&gt;db-&gt;dbprefix . "user_group 
              WHERE user_group_id = '" . (int)$user_query-&gt;row('user_group_id') . "'");
  
          $permissions = unserialize($user_group_query-&gt;row('permission')); // Vardumps fine.
  
          if (is_array($permissions)) {
              foreach ($permissions as $key =&gt; $value) {
                  $this-&gt;permission[$key] = $value;
              }
          }
  
          return true;
      } else {
          return false;
      }
  }
  </code></pre>
  
  <p><strong>Has Permission</strong></p>
  
  <pre><code>public function hasPermission($key, $value) {
      if (isset($this-&gt;permission[$key])) {
          return in_array($value, $this-&gt;permission[$key]);
      } else {
          return false;
      }
  }
  </code></pre>
  
  <p><strong>Var Dump</strong></p>
  
  <pre><code>array(2) { 
  
  ["access"]=&gt; array(18) { 
  
  [0]=&gt; string(18) "catalog/Categories" 
  [1]=&gt; string(27) "code_examples/Code_examples" 
  [2]=&gt; string(23) "dashboard_modules/Chart" 
  [3]=&gt; string(34) "dashboard_modules/Latest_customers" 
  [4]=&gt; string(30) "dashboard_modules/Latest_users" 
  [5]=&gt; string(14) "design/Banners" 
  [6]=&gt; string(14) "design/Layouts" 
  [7]=&gt; string(16) "extension/Module" 
  [8]=&gt; string(15) "module/Category" 
  [9]=&gt; string(16) "module/Slideshow" 
  [10]=&gt; string(43) "module_code_examples/Codeigniter_controller" 
  [11]=&gt; string(38) "module_code_examples/Codeigniter_email" 
  [12]=&gt; string(39) "module_code_examples/Codeigniter_routes" 
  [13]=&gt; string(16) "settings/Setting" 
  [14]=&gt; string(14) "settings/Store" 
  [15]=&gt; string(8) "tool/Log" 
  [16]=&gt; string(10) "user/Users" 
  [17]=&gt; string(17) "user/Users_groups" 
  } 
  
  ["modify"]=&gt; array(18) { 
  
  [0]=&gt; string(18) "catalog/Categories" 
  [1]=&gt; string(27) "code_examples/Code_examples" 
  [2]=&gt; string(23) "dashboard_modules/Chart" 
  [3]=&gt; string(34) "dashboard_modules/Latest_customers" 
  [4]=&gt; string(30) "dashboard_modules/Latest_users" 
  [5]=&gt; string(14) "design/Banners" 
  [6]=&gt; string(14) "design/Layouts" 
  [7]=&gt; string(16) "extension/Module" 
  [8]=&gt; string(15) "module/Category" 
  [9]=&gt; string(16) "module/Slideshow" 
  [10]=&gt; string(43) "module_code_examples/Codeigniter_controller" 
  [11]=&gt; string(38) "module_code_examples/Codeigniter_email" 
  [12]=&gt; string(39) "module_code_examples/Codeigniter_routes" 
  [13]=&gt; string(16) "settings/Setting" 
  [14]=&gt; string(14) "settings/Store" 
  [15]=&gt; string(8) "tool/Log" 
  [16]=&gt; string(10) "user/Users" 
  [17]=&gt; string(17) "user/Users_groups" 
  
  } 
  
  } 
  </code></pre>
  
  <p><strong>Update this is how I use the hasPermission</strong> </p>
  
  <pre><code>public function index() {
      if (($this-&gt;input-&gt;server('REQUEST_METHOD') == 'POST') &amp;&amp; $this-&gt;validateForm()) {
          redirect();
      }
  
      // load view area &amp; content
  }
  
  public function validateForm() {
      if (!$this-&gt;user_auth-&gt;hasPermission('modify', 'folder/controller-name')) {
        // Displays error
      }
  
      // Other checks.
  }
  </code></pre>
  
  <p><strong>Thanks in advance</strong></p>