我正在使用表中的变量填充数组。
由于某种原因,它不喜欢索引 08 或 09。
当我有
$numCorrectArray = array(01=>$q01TotalCorrect, 02=>$q02TotalCorrect, 03=>$q03TotalCorrect, 04=>$q04TotalCorrect, 05=>$q05TotalCorrect, 06=>$q06TotalCorrect, 07=>$q07TotalCorrect, 08=>$q08TotalCorrect, 09=>$q09TotalCorrect, 10=>$q10TotalCorrect, 11=>$q11TotalCorrect, 12=>$q12TotalCorrect, 13=>$q13TotalCorrect, 14=>$q14TotalCorrect, 15=>$q15TotalCorrect, 16=>$q16TotalCorrect, 17=>$q17TotalCorrect, 18=>$q18TotalCorrect, 19=>$q19TotalCorrect, 20=>$q20TotalCorrect, 21=>$q21TotalCorrect, 22=>$q22TotalCorrect, 23=>$q23TotalCorrect, 24=>$q24TotalCorrect, 25=>$q25TotalCorrect, 26=>$q26TotalCorrect, 27=>$q27TotalCorrect, 28=>$q28TotalCorrect, 29=>$q29TotalCorrect, 30=>$q30TotalCorrect, 31=>$q31TotalCorrect, 32=>$q32TotalCorrect, 33=>$q33TotalCorrect, 34=>$q34TotalCorrect, 35=>$q35TotalCorrect, 36=>$q36TotalCorrect, 37=>$q37TotalCorrect, 38=>$q38TotalCorrect, 39=>$q39TotalCorrect, 40=>$q40TotalCorrect);
print_r 吐出
Array ( [1] => 60 [2] => 69 [3] => 38 [4] => 69 [5] => 70 [6] => 47 [7] => 39 [0] => 70 [10] => 56 [11] => 37 [12] => 32 [13] => 24 [14] => 48 [15] => 72 [16] => 65 [17] => 26 [18] => 50 [19] => 55 [20] => 36 [21] => 40 [22] => 49 [23] => 37 [24] => 33 [25] => 66 [26] => 64 [27] => 68 [28] => 54 [29] => 59 [30] => 25 [31] => 58 [32] => 58 [33] => 58 [34] => 48 [35] => 70 [36] => 51 [37] => 67 [38] => 54 [39] => 62 [40] => 45 )
同时,当我这样做时
$numCorrectArray = array(01=>$q01TotalCorrect, 02=>$q02TotalCorrect, 03=>$q03TotalCorrect, 04=>$q04TotalCorrect, 05=>$q05TotalCorrect, 06=>$q06TotalCorrect, 07=>$q07TotalCorrect, 88=>$q08TotalCorrect, 99=>$q09TotalCorrect, 10=>$q10TotalCorrect, 11=>$q11TotalCorrect, 12=>$q12TotalCorrect, 13=>$q13TotalCorrect, 14=>$q14TotalCorrect, 15=>$q15TotalCorrect, 16=>$q16TotalCorrect, 17=>$q17TotalCorrect, 18=>$q18TotalCorrect, 19=>$q19TotalCorrect, 20=>$q20TotalCorrect, 21=>$q21TotalCorrect, 22=>$q22TotalCorrect, 23=>$q23TotalCorrect, 24=>$q24TotalCorrect, 25=>$q25TotalCorrect, 26=>$q26TotalCorrect, 27=>$q27TotalCorrect, 28=>$q28TotalCorrect, 29=>$q29TotalCorrect, 30=>$q30TotalCorrect, 31=>$q31TotalCorrect, 32=>$q32TotalCorrect, 33=>$q33TotalCorrect, 34=>$q34TotalCorrect, 35=>$q35TotalCorrect, 36=>$q36TotalCorrect, 37=>$q37TotalCorrect, 38=>$q38TotalCorrect, 39=>$q39TotalCorrect, 40=>$q40TotalCorrect);
print_r 吐出
Array ( [1] => 60 [2] => 69 [3] => 38 [4] => 69 [5] => 70 [6] => 47 [7] => 39 [88] => 66 [99] => 70 [10] => 56 [11] => 37 [12] => 32 [13] => 24 [14] => 48 [15] => 72 [16] => 65 [17] => 26 [18] => 50 [19] => 55 [20] => 36 [21] => 40 [22] => 49 [23] => 37 [24] => 33 [25] => 66 [26] => 64 [27] => 68 [28] => 54 [29] => 59 [30] => 25 [31] => 58 [32] => 58 [33] => 58 [34] => 48 [35] => 70 [36] => 51 [37] => 67 [38] => 54 [39] => 62 [40] => 45 )
注意它如何处理键 08 和 09 以及我在第二个示例中将它们更改为 88 和 99 时的情况。
有人能发现我做错了什么吗?
在 PHP 中在数字前面添加 0 会强制该数字被解释为八进制值。八进制表示法中没有 8 和 9。
为什么不直接使用 1、2、3 等?或者,如果您确实需要它是两位数字,请使用字符串作为键,即“01”、“02”、“03”...
0...是八进制数,没有 08 或 09,因此 PHP 将它们视为 0。