Tell me more ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

Possible Duplicate:
How to “flatten” a multi-dimensional array to simple one in php?

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've tried multiple things with recursion, all without luck so far...

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

marked as duplicate by Tim Post Nov 13 '11 at 16:02

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.