请问下面这个数组怎么在HTML中遍历出来,试了很多方法还是报错
程序员文章站
2022-06-05 09:18:12
...
Array
(
[bigimg] => Array
(
[0] => Array
(
[id] => 2
[imgtitle] => abc
[imgintro] => asdasd
[filename] => sda.jpg
[imgtype] => indeximg
[created_at] => 2016-10-26 14:58:14
)
[1] => Array
(
[id] => 1
[imgtitle] => sadas
[imgintro] => asdasd
[filename] => 147asda.jpg
[imgtype] => indeximg
[created_at] => 2016-10-24 14:13:12
)
)
[minimg] => Array
(
)
)
现在只想遍历数组bigimg
回复内容:
Array
(
[bigimg] => Array
(
[0] => Array
(
[id] => 2
[imgtitle] => abc
[imgintro] => asdasd
[filename] => sda.jpg
[imgtype] => indeximg
[created_at] => 2016-10-26 14:58:14
)
[1] => Array
(
[id] => 1
[imgtitle] => sadas
[imgintro] => asdasd
[filename] => 147asda.jpg
[imgtype] => indeximg
[created_at] => 2016-10-24 14:13:12
)
)
[minimg] => Array
(
)
)
现在只想遍历数组bigimg
下面这样可符合你的要求?
var bigimg = [
[{id:2},{imgtitle:'abc'},{imgintro:'asdasd'},{filename:'sda.jpg'},{filename:'indeximg'},{created_at:'2016-10-26 14:58:14'}],
[{id:1},{imgtitle:'sadas'},{imgintro:'asdasd'},{filename:'147asda.jpg'},{filename:'indeximg'},{created_at:'2016-10-24 14:13:12'}]
]
var fn = function(arr){
for(var key in arr){
//如果子元素依然是数组或者Object则递归迭代
if(typeof arr[key] =='object'){
fn(arr[key])
}else{
console.log(key+'='+arr[key])
}
}
}
fn(bigimg)
已解决了! 在HTML 引用是 $bigimg[0][id]