Link to home
Start Free TrialLog in
Avatar of P Silva
P Silva

asked on

Use php to convert multidimensional array to a csv file

I'm a php newbie.  I have an array that is the result of a ldap search.  I need to convert the multidimensional array into a file that can is imported by one of our applications.  The import part is automated and file has to delivered in that format.

The array is in the format that follows (I made values generic)

[recordnumber] => Array
        (
            [firstname] => Array
                (
                    [count] => 1
                    [0] => John
                )

            [0] => firstname
            [initials] => Array
                (
                    [count] => 1
                    [0] => R.
                )

            [1] => initials
            [lastname] => Array
                (
                    [count] => 1
                    [0] => smith
                )

            [2] => sn
            [mail] => Array
                (
                    [count] => 1
                    [0] => jsmith@domain.com
                )

            [3] => mail
            [count] => 4
            [dn] => uid=jsmith,dc=domain,dc=com
        )

Files needs to be in this format.  Last field is a value derived on the fly depending on whether person has certain access rights.

|Smith, John R.|jsmith@domain.com||

I found lots of code examples online. None of which I can make work.  I have to flatten the array which seems to be the most difficult part.

Thanks.
ASKER CERTIFIED SOLUTION
Avatar of Ray Paseur
Ray Paseur
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of P Silva
P Silva

ASKER

Thanks for the tips and the quick reply.
Thanks for using EE!  All the best, ~Ray