Do you have a question? Post it now! No Registration Necessary. Now with pictures!
- Posted on
- array of arrays to list of lists
December 27, 2009, 6:16 am
rate this thread
Lets say we have an array of arrays:
$A['first'] = array('one','two','three');
$A['second'] = array('1','2');
and we want to turn this into a list of lists:
This is a fairly common thing to do, say with site maps of pages in
sections, or lists of products in categories.
It seems to me that there must be a straight forward way of making
these such that you could set up a function and feed it the params and
details of what your lists will look like (usually links, and rows of
data from a database) but I can't quite wrap my mind around a clean and
simple way of doing this. I get hung up in the recursive bit.
Who has a solution or hint for this common chore? Or is this a messy
Re: array of arrays to list of lists
Yes. I do this all the time.
There is no recursion involved.
For a start:
foreach($A as $k => $b)
// do stuff with $k
foreach ($b as $c)
//do stuff with $c
// do stuff
Then wrap it up in a class if you wish, bot not a messy one please but one
tailored to your specific requirements.
I'm sure (without even looking) that there is something in the namual
- » sending email with attachement with mail() and local mailserver
- — Next thread in » PHP Scripting Forum