我有一个数组,我试图循环创建一种特定于我当前页面的新型数组。
我的数组如下所示:
//$_SESSION['data'] =
Array (
[0] => 1
[1] => 0
[2] => Tom
[8] => 1
[4] => 1
[5] => Array (
[7] => Array (
[0] => Andrew
[1] => 1
[2] => 1
[4] => 0
[5] => avatar.jpg
[6] => 1
)
)
[6] => Array ( [0] => 1
[1] => 2
)
)
所以在我的 JS 文件中我有这个:
var stats = <? echo json_encode($_SESSION['data'][5]); ?> ; //this is the array
my_data = new Array();
for(var key in stats){
if(key in my_data){} else { //prevent double entry
my_data[key] = new Array();
my_data[key][0] = stats[key][6];
my_data[key][1] = stats[key][5];
my_data[key][2] = stats[key][2];
my_data[key][3] = stats[key][0];
}
}
console.log(my_data);
现在在 console.log 我得到这个:
[undefined × 7, Array[4]
0: "1"
1: "avatar.jpg"
2: "1"
3: "Andrew"
length: 4
__proto__: Array[0]
]
我想知道为什么它说未定义的x7?