Rumah >pembangunan bahagian belakang >tutorial php >请问下面这个数组怎么在HTML中遍历出来,试了很多方法还是报错

请问下面这个数组怎么在HTML中遍历出来,试了很多方法还是报错

WBOY
WBOYasal
2016-12-01 01:27:23951semak imbas

<code>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
        (
        )

)</code>

现在只想遍历数组bigimg

回复内容:

<code>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
        (
        )

)</code>

现在只想遍历数组bigimg

下面这样可符合你的要求?

<code class="javascript">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)</code>

已解决了! 在HTML 引用是 $bigimg[0][id]

Kenyataan:
Kandungan artikel ini disumbangkan secara sukarela oleh netizen, dan hak cipta adalah milik pengarang asal. Laman web ini tidak memikul tanggungjawab undang-undang yang sepadan. Jika anda menemui sebarang kandungan yang disyaki plagiarisme atau pelanggaran, sila hubungi admin@php.cn