How do I flatten an associative array into an array with only values in PHP?

Posted by aalaap on Stack Overflow See other posts from Stack Overflow or by aalaap
Published on 2009-05-30T07:08:35Z Indexed on 2010/04/11 11:53 UTC
Read the original article Hit count: 273

Filed under:
|
|

I have an array that has keys and values. For eg:

Array (
    [name] => aalaap
    [age] => 29
    [location] => mumbai
)

I want to convert the keys from this into values, but I want the values to apear right after the keys. For eg:

Array (
    [0] => name
    [1] => aalaap
    [2] => age
    [3] => 29
    [4] => location
    [5] => mumbai
)

I can easily write an iteration function that will do this... for eg:

array_flatten($arr) {
    foreach ($arr as $arrkey => $arrval) {
        $arr_new[] = $arrkey;
        $arr_new[] = $arrval;
    }
    return $arr_new;
}

...but I'm trying to find out if there's any way this can be accomplished using array_combine, array_keys, array_values and/or array_merge, preferably in one, so i don't need to use a custom function.

Is there?

© Stack Overflow or respective owner

Related posts about php

Related posts about arrays