Search code examples
phpsessionundefinedsession-cookiesundefined-index

what is session_reset() exactly?


I want to know what is session_reset() for and when should we use it ? when I use it I get an error like this: "Call to undefined index session_reset()". I hope you know something about it . Thank you in advance.


Solution

  • session_reset — Re-initialize session array with original values.

    Example

    first create a session variable

     <?php
        session_start();
        $_SESSION["A"] = "Some Value";
       echo $_SESSION["A"];
    
    //Output: Some Value
    
    //if you need to rollback the session values after seting new value to session variables use session_reset()
    
       $_SESSION["A"] = "Some New Value";  // set new value
    
      session_reset();  // old session value restored
       echo $_SESSION["A"];
    
    //Output: Some Value
    ?>