Therefore, when I can not ask, I will answer:
This question is old, but still someone is looking at it like I did, I searched and I liked one of the answers, but here is the best one: Allows unset $ array1, except for some variables like $ array2
function unsetExcept($array1,$array2) { foreach ($array1 as $key => $value) if(!in_array($key, $array2)){ unset($array1[$key]); } } }
Why is it better? THIS IS NOT ONLY FOR $ _SESSION
source share