Is serializing arrays before storing them in session variables a common practice in PHP?

When storing arrays in session variables in PHP, it is common practice to serialize the array before storing it. This is because session variables can only store strings, so serializing the array converts it into a string that can be easily stored and retrieved. When retrieving the array from the session variable, you can then unserialize it to get back the original array data.

// Serialize the array before storing it in a session variable
$array = [1, 2, 3];
$_SESSION['my_array'] = serialize($array);

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