up vote 0 down vote favorite

Hello all,

I'm trying to create a generic database mapping class with PHP. Collecting the data through my functions is going well, but as expected I'm retrieving a nested set.

A print_r of my received array looks like:

Array
(
    [table] => Session
    [columns] => Array
        (
            [0] => `Session`.`ID` AS `Session_ID`
            [1] => `Session`.`User` AS `Session_User`
            [2] => `Session`.`SessionID` AS `Session_SessionID`
            [3] => `Session`.`ExpiresAt` AS `Session_ExpiresAt`
            [4] => `Session`.`CreatedAt` AS `Session_CreatedAt`
            [5] => `Session`.`LastActivity` AS `Session_LastActivity`
            [6] => `Session`.`ClientIP` AS `Session_ClientIP`
        )

    [0] => Array
        (
            [table] => User
            [columns] => Array
                (
                    [0] => `User`.`ID` AS `User_ID`
                    [1] => `User`.`UserName` AS `User_UserName`
                    [2] => `User`.`Password` AS `User_Password`
                    [3] => `User`.`FullName` AS `User_FullName`
                    [4] => `User`.`Address` AS `User_Address`
                )

            [0] => Array
                (
                    [table] => Address
                    [columns] => Array
                        (
                            [0] => `Address`.`ID` AS `Address_ID`
                            [1] => `Address`.`UserID` AS `Address_UserID`
                            [2] => `Address`.`Street` AS `Address_Street`
                            [3] => `Address`.`City` AS `Address_City`
                        )

                )

        )

)

To simplify things I want to recreate this nested array to a flat array so I can easily loop through it and use the 'columns' key to create my SELECT query.

I'm kinda struggling with this for a while now and figures, maybe some users at SO can help me out here.

I've tried multiple things with recursion, all without luck so far...

Any help is much appriciated!

Thanks in advance, Ben Fransen

link|flag

1  
Possibly duplicate. Look at these results: stackoverflow.com/search?q=flatten+array+php – Felix Kling Mar 29 at 15:02
Thanks for noticing, i'll look through those results meanwhile. – Ben Fransen Mar 29 at 15:03

1 Answer

Your Answer

get an OpenID
or
never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.