I hope you can help me I have an array in which I keep numbers that correspond to a specific subject ie they are the id, but I need to go through that array and verify that if the subject is repeated it means that it is the second time that is in the array and so if it comes out a third time is the third for example: mi_array = [1,4,6,7,9,4,1,8,3,4] go through it and print
1=primera
4=primera
6=primera
7=primera
4=segunda
1=segunda
8=primera
3=primera
4=tercera
I hope my explanation is understandable and you can help me
$pdo = new DB();
$no_mat = array();
$query = $pdo->connect()->prepare('SELECT ID_ESTUDIANTE,ID_CARRERA,ID_MATERIA FROM 'calificaciones' WHERE ID_ESTUDIANTE = ?');
$query1 = $pdo->connect()->prepare('SELECT DISTINCT ID_ESTUDIANTE FROM 'calificaciones'');
$query2 = $pdo->connect()->prepare('UPDATE calificaciones SET 'NO_MATRICULA' = ? WHERE ID_ESTUDIANTE = ? AND ID_MATERIA = ?');
$query1->execute();
foreach($query1 as $ids){
$query->execute([$ids[0]]);
foreach($query as $e){
array_push($no_mat,$e[2]);//ESTE ARREGLO GUARDA EL ID DE LA MATERIA
}
//EL PROBLEMA ES QUE SI UNA MATERIA SE REPITE 3 VECES EN LA POSICION QUE ESTE ME SALE 3 Y NECESITO QUE EN LA PRIMERA SALGA 1 EN LA SEGUNDA 2 Y PUES CLARO EN LA TERCERA 3
for($i=0;$i<count($no_mat);$i++){
$cont=(count(array_keys($no_mat, $no_mat[$i])));
if($cont>1 && $cont<3){
$query2->execute([$cont,$ids[0],$no_mat[$i]]);
}elseif($cont>2){
$query2->execute([$cont,$ids[0],$no_mat[$i]]);
}else{
$query2->execute([1,$ids[0],$no_mat[$i]]);
}
}
unset($no_mat);
$no_mat = array();
}