NYCPHP Meetup

NYPHP.org

[nycphp-talk] next() for multidimensional arrays?

David Krings ramons at gmx.net
Wed May 2 20:55:38 EDT 2007


Hi!

Is there anything available like next() that will work on 
multidimensional arrays?
I want to get a flat list of key and value of the current element of a 
multidimensional array. I played around with next() now for an excessive 
amount of time and it just doesn't seem to think in more than one 
dimension. I also cannot make it to without missing some portions of the 
multidimensional array.

Here is what I really want to do:
I copied the dirlist function from the php.net man page for scandir. The 
function really works well, but returns a multidimensional array with 
the folder names being the keys for the subarrays, whereas files have a 
numerical key. What I need is a one dimensional array that has this 
structure:
path_to_folder_as_key => filename1
path_to_folder_as_key => filename2
path_to_folder_as_key => filename3
path_to_folder_as_key => filename4
....

I also spent quite some time with all the various array flattening 
routines, but due to my lack of skill I cannot get those to keep the 
keys in place or even combine them to a path. It is nice that something 
like scandir is finally available, but PHP is still not very helpful in 
that arena. Nah, it's not PHP, it's me being stupid. I also attempted 
recursion with a function myself, but that ended up in total chaos and 
desaster.

It would be great if one of you smart people could beat me out of this 
.... again.

Best regards,

	David



More information about the talk mailing list