How the array in the session variable references

Source: Internet
Author: User
session| Variable | Array If you store an array in a sessions object, you should not attempt to alter the elements of the stored array directly. For example, the following script won't work:

<% session ("StoredArray") (3) = "New Value"%>

This is because the session object is implemented as a collection. The array element StoredArray (3) does not receive the new value. Instead, the value is indexed to the collection, overwriting any information stored in that location.

It is strongly recommended so if you store an array in the Session object, you retrieve a copy of the array before Retri Eving or changing any of the elements of the array. When you are do with the array, you should store the "array in" the Session object again so any changes you made are Saved. This is demonstrated in the following example:

---file1.asp---
<%
' Creating and initializing the array
Dim MyArray ()
Redim MyArray (5)
MyArray (0) = "Hello"
MyArray (1) = "Some other string"

' Storing the ' array in the Session object.
Session ("StoredArray") = MyArray

Response.Redirect ("file2.asp")
%>

---file2.asp---
<%
' Retrieving the ' array from the session Object
' and modifying its second element.
LocalArray = Session ("StoredArray")
LocalArray (1) = "There"

' Printing out the string ' Hello there.
Response.Write (LocalArray (0) &localarray (1))

' Re-storing the ' array in the Session object.
' This overwrites the values in StoredArray with the new values.
Session ("StoredArray") = LocalArray
%>



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.