What are the common data types used in PHP sessions?

Common data types used in PHP sessions include strings, integers, arrays, and objects. When storing data in a PHP session, it's important to ensure that the data type is appropriate for the information being stored. For example, use strings for simple text data, integers for numerical values, arrays for collections of data, and objects for more complex data structures.

// Start the session
session_start();

// Storing a string in a session variable
$_SESSION['username'] = 'JohnDoe';

// Storing an integer in a session variable
$_SESSION['age'] = 30;

// Storing an array in a session variable
$_SESSION['colors'] = array('red', 'green', 'blue');

// Storing an object in a session variable
$user = new stdClass();
$user->name = 'JaneDoe';
$user->age = 25;
$_SESSION['user'] = $user;