Last active
August 29, 2015 14:03
-
-
Save juniorb2ss/5a92ae9ff654e37962e9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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