session_start();
$_SESSION['name_here'] = $your_array;
<?php
//Start your session.
session_start();
//Add a product ID to our cart session variable.
$_SESSION['cart'][] = 2787376;
//Dump it out for example purposes.
var_dump($_SESSION);
//how to access it
<?php
//Start your session.
session_start();
//Make sure that the session variable actually exists!
if(isset($_SESSION['cart'])){
//Loop through it like any other array.
foreach($_SESSION['cart'] as $productId){
//Print out the product ID.
echo $productId, '<br>';
}
}
<?php
$my_arr = array('Saumya', 'Nikita', 'Upasana', 'Dyana');
// use array_push to add 3 elements to end of $my_arr
$new_num = array_push($my_arr, 'Adhikar', 'sanjay', 'Puspendra', 'Mukesh');
// inspect return value of array_push
echo $new_num;
print_r($my_arr);
?>
//my ex
$id = $_GET['PId'];
// $cartArray = array(
// );
// array_push($cartArray, $id);
session_start();
// $_SESSION["cart"] = $cartArray;
$_SESSION['cart'][] = $id;
header("Content-type:application/json");
echo json_encode($_SESSION["cart"]);
<input type="hidden" id="sess_var" value="<?php echo $_SESSION['is_logged']; ?>"/>
var session = document.getElementById('sess_var').value;
alert(session);