I am populating an array with variables from a table.
For some reason, it doesn't like the indexes 08 or 09.
When I have
$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 spits out
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 )
Meanwhile, when I do
$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 spits out
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 )
Notice how it handles keys 08 and 09 vs when I change them to 88 and 99 in the second example.
Can anyone spot what I am doing wrong?
Preppending a number with a 0 in PHP forces the number to be interpreted as an octal value. There is no 8 and 9 in octal notation.
Why not just use 1, 2, 3, etc? Or if you really need it to be two digits, use strings as key, i.e. '01', '02', '03'...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With