Action after the end of the foreach

Asked

Viewed 37 times

0

Well, I have one foreach and would like to run some script right after it comes to an end. But how do I do this check?

foreach ($array as $id_video) {
   $resultado = mysqli_query($conexao, "INSERT INTO exercicios (id_treino_exercicio, id_aluno_exercicio, dia_exercicio) VALUES ('$id_video', '$id_aluno_exercicio', '$dia_exercicio')");
}
  • 1

    Just put some code after the block foreach, No? If he "passed" the foreach, you don’t have to check, because you know he’s "done"...

1 answer

1


To perform an action after the foreach, just put the code at the end.

foreach ($array as $key => $value) {
      // Código dentro do loop
}

// Código depois do foreach
echo "Foreach finalizado com sucesso";

The code provided within foreach is executed and only after the end of the loop is the subsequent code used.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.