What is the purpose of using multidimensional arrays in PHP sessions?

Using multidimensional arrays in PHP sessions allows you to store and retrieve complex data structures within a session. This can be useful when you need to store related data together, such as user information with multiple fields. By using multidimensional arrays, you can organize and access this data more efficiently within the session.

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

// Store user information in a multidimensional array
$_SESSION['user'] = array(
    'username' => 'john_doe',
    'email' => 'john.doe@example.com',
    'role' => 'admin'
);

// Retrieve and display user information
echo $_SESSION['user']['username']; // Output: john_doe
echo $_SESSION['user']['email']; // Output: john.doe@example.com
echo $_SESSION['user']['role']; // Output: admin
?>