PHP : flatten array - fastest way?

Posted by Industrial on Stack Overflow See other posts from Stack Overflow or by Industrial
Published on 2010-05-28T16:43:12Z Indexed on 2010/05/28 16:51 UTC
Read the original article Hit count: 150

Filed under:
|
|
|

Is there any fast way to flatten an array and select subkeys ('key'&'value' in this case) without running a foreach loop, or is the foreach always the fastest way?

Array
(
    [0] => Array
        (
            [key] => string
            [value] => a simple string
            [cas] => 0
        )

    [1] => Array
        (
            [key] => int
            [value] => 99
            [cas] => 0
        )

    [2] => Array
        (
            [key] => array
            [value] => Array
                (
                    [0] => 11
                    [1] => 12
                )

            [cas] => 0
        )

)

To:

Array
(
    [int] => 99
    [string] => a simple string
    [array] => Array
        (
            [0] => 11
            [1] => 12
        )
)

© Stack Overflow or respective owner

Related posts about php

Related posts about Performance