"how to remove a variable from a php session array" Code Answer

2
if (isset($_post['remove'])) {
    $key=array_search($_get['name'],$_session['name']);
    if($key!==false)
    unset($_session['name'][$key]);
    $_session["name"] = array_values($_session["name"]);
} 

since $_session['name'] is an array, you need to find the array key that points at the name value you're interested in. the last line rearranges the index of the array for the next use.

By Ben2307 on January 14 2022

Answers related to “how to remove a variable from a php session array”

Only authorized users can answer the Search term. Please sign in first, or register a free account.