I have some session data in a website. I want to destroy all session data when user click another page, except some specific keys like $_SESSION[\'x\'] and
As $_SESSION is a regular array, you can use array_intersect_key to get your resulting array:
$keys = array('x', 'y');
$_SESSION = array_intersect_key($_SESSION, array_flip($keys));
Here array_flip is used to flip the key/value association of $keys and array_intersect_key is used to get the intersection of both arrays while using the keys for comparison.