Answers for "session array"

PHP
0

php session array

session_start();
 $_SESSION['name_here'] = $your_array;
Posted by: Guest on October-09-2021
0

session 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>';
    }
}
Posted by: Guest on January-08-2022

Browse Popular Code Answers by Language