What is the best practice for storing button press events in PHP sessions?

When storing button press events in PHP sessions, it is best practice to use an array to store the events. This allows you to easily add new events to the array without overwriting previous ones. You can then save this array in the session variable to keep track of all button press events during the user's session.

// Start the session
session_start();

// Check if the button press event array exists in the session
if (!isset($_SESSION['button_press_events'])) {
    $_SESSION['button_press_events'] = [];
}

// Add the new button press event to the array
$_SESSION['button_press_events'][] = "Button X pressed";

// Display all button press events
print_r($_SESSION['button_press_events']);