Hi, I'm very new to PHP so I hope this is not frustrating. I'm having trouble understanding how "isset" works. I'm trying to get it so that when I click a button, it returns two variables(in an array). This works, but I tried to use "Isset" to detect if a array was created, then alter the variable. It's not working... I'm not too sure where I'm going wrong, could anyone give me some advice? Thanks
<?php
if(isset($_POST['name']))
{
$userAnswer = $_POST['name'];
if(isset($_SESSION['test'])){
$_SESSION['test'][$userAnswer]['var1']++;
$test = $_SESSION['test'][$userAnswer];
foreach ($test as $key){
echo json_encode($key);
};
}
else {
$test = $_SESSION['test'][$userAnswer]=array("var1" => 1, "var2" => 2);
foreach ($test as $key){
echo json_encode($key);
};
}
}
?>
$(document).ready(function(){
$("button").click(function(){
var test = "here";
$.ajax({
url: 'info.php',
type: "POST",
dataType:'json',
data: ({name: test}),
success: function(data){
$("#click").fadeOut(function() {
$(this).append(data);
}).fadeIn();
}
});
});
});