dongmei1828 2015-01-31 09:44
浏览 28
已采纳

PHP:echo多维数组

i have an array output like this :

Array
(
    [2015-01-23] => Array
        (
            [0] => Array
                (
                    [orgdate] => 2015-01-23
                    [origin] => india
                )

        [1] => Array
            (
                [orgdate] => 2015-01-23
                [origin] => us
            )

        [2] => Array
            (
                [orgdate] => 2015-01-23
                [origin] => england
            )

        [3] => Array
            (
                [orgdate] => 2015-01-23
                [origin] => india2
            )

        [4] => Array
            (
                [orgdate] => 2015-01-23
                [origin] => uae
            )

        [5] => Array
            (
                [orgdate] => 2015-01-23
                [origin] => africa
            )

        [6] => Array
            (
                [orgdate] => 2015-01-23
                [origin] => china
            )

        [7] => Array
            (
                [orgdate] => 2015-01-23
                [origin] => hongkong
            )

        [8] => Array
            (
                [orgdate] => 2015-01-23
                [origin] => africa2
            )

        [9] => Array
            (
                [orgdate] => 2015-01-23
                [origin] => africa3
            )

        [10] => Array
            (
                [orgdate] => 2015-01-23
                [origin] => africa4
            )

        [11] => Array
            (
                [orgdate] => 2015-01-23
                [origin] => africa5 
            )

    )

[2015-01-14] => Array
    (
        [0] => Array
            (
                [orgdate] => 2015-01-14
                [origin] => japan1
            )

        [1] => Array
            (
                [orgdate] => 2015-01-14
                [origin] => japan2
            )

        [2] => Array
            (
                [orgdate] => 2015-01-14
                [origin] => japan3
            )

        [3] => Array
            (
                [orgdate] => 2015-01-14
                [origin] => japan4
            )

    )

[2015-01-13] => Array
    (
        [0] => Array
            (
                [orgdate] => 2015-01-13
                [origin] => russia
            )

    )

)

now i want to display 2015-01-23 , 2015-01-14 , 2015-01-13 and then each inner contents

origin: india
origin: usa
origin: england , etc....

how i accomplish this.? i already tried recursive function like this , but this couldn't find solution

any help would be greatly appreciated

  • 写回答

2条回答 默认 最新

  • dongshen2903 2015-01-31 09:50
    关注

    you don't need a recursion as your array is flat (only 1 deep)

    I'm not sure what you want but:

    foreach($array as $key=>$subarray)
    {
        echo $key;
        foreach($array[$key] as $subarray)
        {
            echo "origin".$subarray["origin"];
        }
    }
    

    this should work. If you just want to see for debug, use var_dump($array);

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 python使用pulp线性优化时报错
  • ¥15 开源或低价数据中台哪个最好
  • ¥15 arduino编程出现字符串疑似覆盖现象
  • ¥15 我的b站在没有碰到屏幕的情况下偶尔会自动跳出进度条,就像在屏幕上点了一下一样,但我并没有点。而且视频进度并没有变。这可能是什么原因造成的?
  • ¥30 STK matlab python仿真
  • ¥15 关于IMageEnView 图标定位问题
  • ¥20 求解答(matlab)
  • ¥30 ffmpeg库使用过程中遇到的问题
  • ¥15 pyqt5 中python如何通过Qtwebchannel主动发消息给web前端
  • ¥15 关于HTML中title获取xml内容的问题