Is it possible to store whole arrays in session variables in PHP?

Yes, it is possible to store whole arrays in session variables in PHP by serializing the array before storing it and then unserializing it when retrieving it from the session. This allows you to store complex data structures in session variables.

<?php

// Start the session
session_start();

// Define an array
$array = ['apple', 'banana', 'cherry'];

// Serialize the array and store it in a session variable
$_SESSION['my_array'] = serialize($array);

// Retrieve the array from the session and unserialize it
$retrieved_array = unserialize($_SESSION['my_array']);

// Output the retrieved array
print_r($retrieved_array);

?>