Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/vba/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php excelvba中的多维关联数组_Php_Vba_Excel - Fatal编程技术网

Php excelvba中的多维关联数组

Php excelvba中的多维关联数组,php,vba,excel,Php,Vba,Excel,我试图在Excel VBA中创建一个变量,该变量包含“php”中类似的数据 $classroom['group1']['sub_group1']['John']['math']['pretest'] = 20; $classroom['group1']['sub_group1']['John']['math']['posttest'] = 50; $classroom['group1']['sub_group1']['John']['science']['pretest'] = 26; $cla

我试图在Excel VBA中创建一个变量,该变量包含“php”中类似的数据

$classroom['group1']['sub_group1']['John']['math']['pretest'] = 20;
$classroom['group1']['sub_group1']['John']['math']['posttest'] = 50;
$classroom['group1']['sub_group1']['John']['science']['pretest'] = 26;
$classroom['group1']['sub_group1']['John']['science']['posttest'] = 45;

$classroom['group1']['sub_group1']['David']['math']['pretest'] = 40;
$classroom['group1']['sub_group1']['David']['math']['posttest'] = 44;
$classroom['group1']['sub_group1']['David']['science']['pretest'] = 15;
$classroom['group1']['sub_group1']['David']['science']['posttest'] = 17;

$classroom['group1']['sub_group2']['Kate']['math']['pretest'] = 15;
$classroom['group1']['sub_group2']['Kate']['math']['posttest'] = 30;
$classroom['group1']['sub_group2']['Kate']['science']['pretest'] = 26;
$classroom['group1']['sub_group2']['Kate']['science']['posttest'] = 40;

$classroom['group1']['sub_group2']['Alice']['math']['pretest'] = 14;
$classroom['group1']['sub_group2']['Alice']['math']['posttest'] = 35;
$classroom['group1']['sub_group2']['Alice']['science']['pretest'] = 28;
$classroom['group1']['sub_group2']['Alice']['science']['posttest'] = 42;

echo json_encode($classroom);
我想要的结果应该是继承权结构,如下图所示

我试图使用字典,但我的数据与密钥重复

我应该怎么做才能得到我想要的结果,我应该使用什么样的变量类型


谢谢。

问题是。。。为什么你的字典有一个重复的键?(它在哪个级别上有?)第一个
字典应该有一个键(
“group1”
)。作为
“group1”
值的
字典应该有两个键(
“sub\u group1”
“sub\u group2”
)。作为
“sub_group1”
值的
字典应该有两个键(
“John”
和“
David
”)。
“John”
字典和
“David”
字典都应该有两个键(
“math”
“science”
),等等。这些
字典
对象都不会有重复的键。最好将代码包含在问题中。如果您希望在Excel中使用这些数据,最好记住Excel基本上是三维的,包括图纸、列和行。第四个维度可以通过使用不同的工作簿来实现。但是,您描述的任务可以在单个工作表上轻松解决,即二维,即二维数组。您可以使用simple
VBA.Collection
type。为
创建您自己的类,该类将包含
子组的集合
将包含
人的集合
将包含
主题的集合
等:)。
字典
也是可能的,但我想在这里收集就足够了。为了能够将项目添加到字典中,尽管每个项目必须具有唯一的ID。对于VBA.Collection,您也可以使用key,但对于某些项目,您可以使用类似于
包的Collection。如果你有
json
数据并且需要在
VBA
中解析它们,那么一些
json
解析器已经存在了,例如,问题是。。。为什么你的字典有一个重复的键?(它在哪个级别上有?)第一个
字典应该有一个键(
“group1”
)。作为
“group1”
值的
字典应该有两个键(
“sub\u group1”
“sub\u group2”
)。作为
“sub_group1”
值的
字典应该有两个键(
“John”
和“
David
”)。
“John”
字典和
“David”
字典都应该有两个键(
“math”
“science”
),等等。这些
字典
对象都不会有重复的键。最好将代码包含在问题中。如果您希望在Excel中使用这些数据,最好记住Excel基本上是三维的,包括图纸、列和行。第四个维度可以通过使用不同的工作簿来实现。但是,您描述的任务可以在单个工作表上轻松解决,即二维,即二维数组。您可以使用simple
VBA.Collection
type。为
创建您自己的类,该类将包含
子组的集合
将包含
人的集合
将包含
主题的集合
等:)。
字典
也是可能的,但我想在这里收集就足够了。为了能够将项目添加到字典中,尽管每个项目必须具有唯一的ID。对于VBA.Collection,您也可以使用key,但对于某些项目,您可以使用类似于
包的Collection。但在这种情况下,您不能通过键访问它们,但您必须逐个枚举它们。如果您有
json
数据,并且需要在
VBA
中解析它们,那么
VBA
的一些
json
解析器已经存在,例如。