Find equal values in two PHP arrays

0

I'm working on CodeIgniter I'm calling two result() and I want to buy the data in the view.

Model

public function getallData()
  {
    $this->db->order_by('id', 'desc');
    $query = $this->db->get('Data');
    if ($query->num_rows() > 0) {
      return $query->result();
    } else { return false; }
  }

    public function getWhere($id)
    {
      $query = $this->db->get_where('Table', array(
        'status' => $id
      ));
      if ($query->num_rows() > 0) {
        return $query->result();
      }
    } 

Controller

 public function index()
  { $status = 'On';

        $data['datos']=$this->m->getallData();
        $data['tecnicos']=$this->m->getWhere($status);


    $this->load->view('list',$data);

  }

I have this view but I repeat the data: /

<?php if ($datos): ?>
    <?php foreach ($datos as $dato): ?>
        <?php foreach ($tecnicos as $tecnico): ?>
         <?php if ($dato-> id == $tecnico-> id_tec): ?>
               <?php echo 'H'; ?>
          <?php endif; ?>
     <?php endforeach; ?>
  <?php endforeach; ?>
  

I hope you have explained me well

    
asked by MoteCL 12.06.2018 в 23:51
source

1 answer

0

What happens that from the side of the view, where you have embedded the PHP code the way you are iterating, you need to get the value of each array, example:

for ($datos as $dato => $valueDato) {....}

And if you also want to recover the repeated data it would be to add another array where you can store the repeated values, therefore the code would look like this:

$arrayAux = array(10);
$i = 0;
if ($datos) { 
  foreach ($datos as $dato => $valueDato) {
      foreach ($tecnicos as $tecnico => $valueTecnico) {
            if($valueTecnico ==  $valueDato) {
                 if(!in_array($valueTecnico,$arrayAux)) {
                         $arrayAux[$i] =  $valueTecnico;                          
                          $i++; 
                 }    
            }
       }
   }
}

Annex evidence that the code is functional, Regards.

    
answered by 13.06.2018 / 20:54
source