因此,我通过手动添加每个条目来创建一个数组:

$Sections[] = "A.1.4.1";//900 0 900 0 900 900 888 800 800 913 900 900 900
$Sections[] = "A.1.4.2.1";// 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 994 976 954 900 846 779 516 430 344 328 239 150
$Sections[] = "A.1.4.2.2";//900 900 900 900 900 900 900 900 900 900 850 800 750 700 650 600 550 500 376 356 336 227
$Sections[] = "A.1.4.2.3";//1000 1000 1000 1000 900 900 1000 1000 1000 1000 893 803 763 492 516 491 336 336 240 24
$Sections[] = "A.1.4.3";//1000 1000 879 588 560 366 192 867 807 665
$Sections[] = "A.1.4.4";//1000 1000 1000 1000 994 864 620 456 1000 1000 1000
$Sections[] = "A.1.5.1";//900 0 900 800 464
$Sections[] = "A.1.5.2";//a 1000 1000 846 240
$Sections[] = "A.1.5.2";//b 900 900 700 356 
$Sections[] = "A.1.5.3";//1000 879 192
$Sections[] = "A.1.5.4";//1012 922 456

//EU_A
$Sections[] = "A.2.5.1";//a 1048 1048 1048 1048 1004 800 576 378
$Sections[] = "A.2.5.1";//b 1048 1048 1048 1048 1004 820 592 384
$Sections[] = "A.2.5.2";//a 1048 1048  964  828  672 504 340 
$Sections[] = "A.2.5.2";//b 1048 1048  972  836  696 536 376
$Sections[] = "A.2.5.3";//a 1048 1048 1048 1048 1004 800 576 378
$Sections[] = "A.2.5.3";//b  944  944  944  944  944 820 592 384
$Sections[] = "A.2.5.3";//c 1048 1048 1048 1048 1004 820 592 384
$Sections[] = "A.2.5.4";//a 1048 1048 1048  910  776 560 308
$Sections[] = "A.2.5.4";//b  944  944  944  928  804 588 348
$Sections[] = "A.2.5.4";//c 1048 1048 1048  928  804 588 348
$Sections[] = "A.2.7.1";//   560  504  424  304  240 200
$Sections[] = "A.2.7.2";//   520  448  416  360  312 280

//EU_B
$Sections[] = "B.2.4.1";
$Sections[] = "B.2.4.1";
$Sections[] = "B.2.4.2";
$Sections[] = "B.2.4.2";
$Sections[] = "B.3.4.1";
$Sections[] = "B.3.4.1";
$Sections[] = "B.3.4.2";
$Sections[] = "B.3.4.2";

//TR-114
$Sections[] = "A.2.1";
$Sections[] = "A.2.2";

(您可以随意忽略评论,这实际上是我的代码中的剪切和粘贴)

我的问题是当我这样做

return $Sections;

然后尝试引用任何索引,我会遇到一个错误的错误。

但是,如果我这样做

$return[] = $Sections;

return $return;

我很容易参考索引。

我已经彻底阅读了数组的文档,但是我不明白为什么要这样做。我知道它有效,我想知道为什么。

我只能假设,当$ pection段数组传递给$返回数组时,索引以某种方式“刷新”或“更新”。

编辑:我忘了提到它在一个函数中,它返回内部创建的数组。我敢肯定,每个人都会很快掌握这么快,回报陈述和所有

有帮助吗?

解决方案

如果您试图访问索引 $Sections["B.2.4.1"], ,这将不起作用,因为这不是您定义它们的方式。通过使用 [] 语法要附加到数组,您正在创建数字索引。

您的阵列确实看起来如下 [] 用数字索引附加到数组末端:

$Sections[0] = "A.1.4.1";
$Sections[1] = "A.1.4.2.1";
 // etc

其他提示

您没有在代码中指定索引。这 [] 符号意味着PHP将插入元素 在最后 数组,并为其分配一个新的数字索引。

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top