How do I get the Array value using Codeigniter

10,722

Solution 1

don't put entire array in return i.e

foreach ($query->result() as $row)
{
   $return[] = $row->regra_descricao;
}
return $return;

THEN

you can easily find using:

if(in_array('clientes_cadastrar',$permissoes[**'areas'**])){}

hope this helps

Solution 2

U can use the same scope.

 $this->db->select('modulo_regra.regra_descricao');
     $this->db->from('modulo_regra');
     $this->db->where('modulo_regra.modulo_regra_id', id);
     $query = $this->db->get();

    foreach ($query->result() as $row)
    {
       $permissoes = array['areas'];
    }

    $this->session->set_userdata($permissoes);
Share:
10,722
Gabriel Scavassa
Author by

Gabriel Scavassa

Software Engineer with experiences on Backend, frontend, software management, team management and working full remote. Projects I have being : Unodigital, Assets Management and Monitoring for Large Industries. Subway, POS Management System. (Home Office, Team Based in CT, USA) MStech, E-Learning Platforms. Tech Stack: C#, .NetCore and .Net Framework SQL Server MongoDB Azure Go (Golang) : APIs using GorillaMux and Fasthttp Angular (<2) Dart/flutter (minor) Also have experience managing Jenkins for Continuous Integration and Deployment using PowerShell Scripts. I do like to test new technologies, choose tools to support and/or improve working process or features, exploring and creating reusable and objectiveness features or tools that can be easily integrated to main projects or compose a group of subsystems. https://github.com/j-ew-s https://www.linkedin.com/in/gabriel-alves-scavassa/

Updated on June 05, 2022

Comments

  • Gabriel Scavassa
    Gabriel Scavassa almost 2 years

    I have this select

        $this->db->select('modulo_regra.regra_descricao');
        $this->db->from('modulo_regra');
        $this->db->where('modulo_regra.modulo_regra_id', id);
        $query = $this->db->get();
    

    that return to me 2 elements in

      return $query->result_array();
    

    Then I put the return in a Array

       $permissoes =array('areas' => $this->Regra_model->user_has($regra['regra_id']));
    

    then I the $permissoes to the session

       $this->session->set_userdata($permissoes);
    

    So the real problem comes here. when I'm loading the value from session

       $permissoes = array('areas');
       $permissoes = $this->session->userdata('areas'); 
    

    this is its content:

    array(2) ([0] => array(1) ([regra_descricao] => (string) clientes_cadastrar)
              [1] => array(1) ([regra_descricao] => (string) clientes_visualizar))
    

    So i can't validate it with the in_array(), or other way...I would like to know if there is how if there is away to compare the value in this array with one another variable

    like

    if(in_array('clientes_cadastrar',$permissoes)){}
    

    I'm new on it... so sorry for the way i ask.