phparraysmultidimensional-arraytranspose

Transpose a multidimensional array containing elements with inconsistent depths


I have array that looks like this,

    Array
(
    [email_address] => Array
        (
            [0] => sadasdasd
            [1] => Simosdsad
        )

    [firstname] => Array
        (
            [0] => sadsadas
            [1] => simon
        )

    [surname] => Array
        (
            [0] => asdasdasdasdasd
            [1] => ainley
        )

    [companies_company_id] => 
    [save_user] => Save User
)

all the keys [0] are related is there away to make these there own array?


Solution

  • A simple way to do this would be something like this:

    $newArray = array();
    foreach($array as $key => $value)  {
        $newArray[] = $value[0];
    }
    

    Is there a reason you haven't?