How can an array be stored in a session in PHP?

To store an array in a session in PHP, you can simply assign the array to a session variable using the $_SESSION superglobal. This allows you to access the array across different pages during the same session.

<?php
// Start the session
session_start();

// Create an array
$array = array("apple", "banana", "cherry");

// Store the array in a session variable
$_SESSION['myArray'] = $array;

// Access the array from the session
$storedArray = $_SESSION['myArray'];

// Output the stored array
print_r($storedArray);
?>