当前位置: 动力学知识库 > 问答 > 编程问答 >

php - Setting up multi-dimensional array in VBScript

问题描述:

I am converting a php program over to VBScript for ASP. I am stuck trying to find a way to structure a multi-dimensional array and could use some help.

Here is how it sets up in the php version:

// $_SESSION[model name][level name][menu name] => [state]

$_SESSION[$model] = array('level_name' => array('menu_name' => array()));

and then here is how I set a value later on

$_SESSION[$model][$level_name][$menu_name] = array('menu_state' => 'UNCHECKED');

Here is what I tried in VBScript that doesn't work

Session(model).Add "level_name", Array()

Session(model)("level_name").Add "menu_name", Array()

Session(model)("level_name")("menu_name").Add "menu_state", Array()

and then try to set the value

Session(model)(level_name)(menu_name)("menu_state") = "UNCHECKED"

but I end up with the very helpful 500 Server Error.

Any ideas?

网友答案:

You need a Dictionary of Dictionaries:

  Dim dicX : Set dicX = CreateObject("Scripting.Dictionary")
  Set dicX("A") = CreateObject("Scripting.Dictionary")
  Set dicX("A")("B") = CreateObject("Scripting.Dictionary")
  Set dicX("A")("B")("C") = CreateObject("Scripting.Dictionary")
  dicX("A")("B")("C")("D") = "WhatEver"
  WScript.Echo dicX("A")("B")("C")("D")
分享给朋友:
您可能感兴趣的文章:
随机阅读: