Skip to content

Instantly share code, notes, and snippets.

@juniorb2ss
Last active August 29, 2015 14:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save juniorb2ss/5a92ae9ff654e37962e9 to your computer and use it in GitHub Desktop.
Save juniorb2ss/5a92ae9ff654e37962e9 to your computer and use it in GitHub Desktop.
<?php
//INICIALIZA A SESSÃO
session_start();
$_SESSION["disciplinas"] = array(1 => 'curso 1', 2 => 'curso 2');
$_POST["disciplinas"] = array(3 => 'curso');
// Verifica se há chamadas de POST
if(!empty($_POST))
{
// Percorre o POST
foreach ($_POST["disciplinas"] as $key => $value)
{
// Pergunta se a disciplina informada já pertence a session
if(!isset($_SESSION["disciplinas"][$key]))
{
// Caso não encontrada é inserida no final da array;
$_SESSION["disciplinas"] = $_SESSION["disciplinas"] + $_POST['disciplinas'][$key];
}
}
/**
* output: array(3) { [1]=> string(7) "curso 1" [2]=> string(7) "curso 2" [3]=> string(5) "curso" }
*/
//echo "<meta HTTP-EQUIV='Refresh' CONTENT='0;URL=dependencia.php'>";
}
else
{
echo "Você não marcou as opções!";
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment