session变量中的数组如何引用

session|变量|数组

If you store an array in a Session object, you should not attempt to alter the elements of the stored array directly. For example, the following script will not 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 into the collection, overwriting any information stored at that location.

It is strongly recommended that if you store an array in the Session object, you retrieve a copy of the array before retrieving or changing any of the elements of the array. When you are done with the array, you should store the array in the Session object again so that 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
%>

时间: 2024-08-28 05:59:27

session变量中的数组如何引用的相关文章

session变量中的数组如何引用?

session|变量|数组 If you store an array in a Session object, you should not attempt to alter the elements of the stored array directly. For example, the following script will not work:<br><br><% Session("StoredArray")(3) = "new v

session变量可以申请数组吗?

session|变量|数组 If you store an array in a Session object, you should not attempt to alter the elements of the stored array directly. For example, the following script will not work:<br><br><% Session("StoredArray")(3) = "new v

如何取得所有的Session变量

session|变量|session 在程序调试中,有时候需要知道有多少Session变量在使用,她们的值如何?由于Session对象提供一个称为Contents的集合(Collection),我们可以通过For...Each循环来达到目标:Dim strName, iLoopFor Each strName in Session.ContentsResponse.Write strName & " - " & Session.Contents(strName)&

代码段1---列出你的所有Session变量

session|变量 <%@ Language=VBScript %><% Option Explicit %><%    Response.Write "在你的程序中一共使用了 " & Session.Contents.Count & _             " 个Session变量<P>"   Dim strName, iLoop   For Each strName in Session.Conte

ASP所有的Session变量获取实现代码_应用技巧

复制代码 代码如下: Dim strName, iLoop For Each strName in Session.Contents Response.Write strName & " - " & Session.Contents(strName)& "[BR]" Next 一般情况下,上面的代码可以工作得很好.但当Session变量是一个对象或者数组时,打印的结果就不正确了. 这样我们修改代码如下: 复制代码 代码如下: '首先看看有多少

ASP所有的Session变量获取实现代码

复制代码 代码如下: Dim strName, iLoop For Each strName in Session.Contents Response.Write strName & " - " & Session.Contents(strName)& "[BR]" Next 一般情况下,上面的代码可以工作得很好.但当Session变量是一个对象或者数组时,打印的结果就不正确了. 这样我们修改代码如下: 复制代码 代码如下: '首先看看有多少

PHP中session变量的销毁

本篇文章主要是对PHP中session变量的销毁进行了介绍,需要的朋友可以过来参考下,希望对大家有所帮助 1.何为session? 相当于一个客户端(可以是浏览器.app.ftp等其他,而且同一个浏览器多开几个又算是不同的客户端)对服务器的一个访问,这个期间服务器为此建立一个唯一的标示(session_id session_name),其实也就是一个数组Array(),Session的开始和结束并不以业务上的输入用户名密码开始,也不以关闭浏览器和网页刷新而结束 2.session变量的销毁 程序

PHP中session变量的销毁_php技巧

1.何为session?相当于一个客户端(可以是浏览器.app.ftp等其他,而且同一个浏览器多开几个又算是不同的客户端)对服务器的一个访问,这个期间服务器为此建立一个唯一的标示(session_id session_name),其实也就是一个数组Array(),Session的开始和结束并不以业务上的输入用户名密码开始,也不以关闭浏览器和网页刷新而结束 2.session变量的销毁程序代码<?phpsession_unset();session_destroy();?> session_un

js中数组的引用的例子

js中数组的引用应该算是基础知识了: var arr = [1,2,3]; var arr2 = arr; arr2[0] = 5;  //此时arr和arr2都变成了[5,2,3] 我们怎么斩断这种引用呢?我所知道的有两个方法: 1.数组的slice方法 var arr = [1,2,3]; var arr2 = arr.slice(); arr2[0] = 5;  //此时arr为[1,2,3]  arr2为[5,2,3] slice方法相当于复制出来一个新数组 2.数组的concat方法