有没有办法在Javascript中初始化空数组,在php中初始化相同的空数组?
$blah = array("0" => "wew", "1" => "fdafa");
foreach ($blah as $blat => $val) {
$arr[] = $val
$arr[$blah][] = 1;
}
或者只是
foreach ($blah as $blat => $val) {
$arr[] = $val
}
答案 0 :(得分:0)
不,您必须声明var
并在将项目推送到[]
之前将其初始化为var blah = {"0":"wew", "1":"fdafa"}; // an object, not an array
var arr = [];
var obj = {}
for (var blat in blah) {
var val = blah[blat];
arr.push(val);
obj[blat] = 1;
}
。
{{1}}