Check selected categories

0

I need to check if the categories chosen by the user exist in the categories suggested by the php system

I have been able to write to the array the categories chosen by the user and also categories suggested by the system.

foreach($array_id_categoria_escolhida as $value_as){
   echo $value_as;
}

echo " ";

foreach($array_categoria_sugerida as $value_ass){
   echo $value_ass;
}

How can I join these two foreach and check if the user has selected the categories suggested by the system?

    
asked by anonymous 15.03.2017 / 16:04

1 answer

0

The logic is more or less this, did not test the code but is likely to work

foreach($array_categoria_sugerida as $value_ass){

    $resul = array_search($value_ass, $array_id_categoria_escolhida);

if ($resul != false){

    $iguais[] = $resul;

  }
}

if(isset($iguais)) {
    foreach($iguais as $valor) {
        $res[] = $array_id_categoria_escolhida[$valor];
    }
}

//todas que batem
var_dump($res);
    
15.03.2017 / 17:04