从单个数组中获取值

时间:2011-05-26 17:26:39

标签: php

  

可能重复:
  How to find the value from this array in php?

hello coders。我有一个像这样的数组

Array
(
    [0] => Array
        (
            [0] => admin/login
            [1] => LoginHandler
            [2] => index
        )

    [1] => Array
        (
            [0] => post
            [1] => PostHandler
            [2] => index
        )

    [2] => Array
        (
            [0] => post/create
            [1] => postHandler
            [2] => create
        )

    [3] => Array
        (
            [0] => post/update
            [1] => postHandler
            [2] => update
        )

    [4] => Array
        (
            [0] => post/delete
            [1] => postHandler
            [2] => delete
        )

)

我只想要像admin/login, LoginHandler,index,这样的值 post,PostHandler,indexpost/create,PostHandler,create等等。那怎么做?

1 个答案:

答案 0 :(得分:2)

您可以遍历数组以对每个元素执行操作:

foreach ( $your_array as $element ) {
    if ( is_array( $element ) ) {
        foreach ( $element as $sub_element ) {
            // You can store this value in a variable, or output it in your desired format.
            echo $sub_element . "<br />";
        }
    }
    else {
        echo $element . "<br />";
    }
}