mardi 20 juin 2017

Browse and compare two arrays

I need to compare an array that comes from a query, with a base array where I have the values that could have the array that comes from the query, the question is how to go through and compare the two arrays so that I get zero where the values do not match And give me the value of the array ?.

this is my code:

public function age_range_men()
    {       
        $type = 'brands';
        $id_array= 75;
        $date_start= '2017-01-02 00:01:00';
        $date_end='2017-03-31 23:59:59';
        $datos = $this->statistics_model->range_age_men($type, $id_array, $date_start, $date_end);

        $result = array();

        foreach($datos as $dato) {
            $result[] = array((string)$dato->rango, (int)$dato->conexiones );
        }

         $base= array(array('12 a 17'), array('18 a 24'),array('25 a 34'), array('35 a 44'), array('45 a 54'),array('55 a 64'),array('mas de 65'));


$res = array();

foreach ($base as $base1) {
    // print_r($base1[0]);
 //       echo "<br>";
    foreach ($result as $result2){
       // print_r($result2[0]);
       // echo "<br>";

        if ($base1[0][0] == $result2[0][0]){
              $res=$result2[1];

              print_r($res);
        }else{

            echo 0;
            break;
        }

    }
  }
}

Aucun commentaire:

Enregistrer un commentaire