2D => 3D conversion
Posted: Wed Dec 28, 2005 6:27 pm
This should be elementary programming, and I distincltly remeber being taught this, but for the life of me I can't remeber and can't figure out how to do it. I have an array of two dimensions, where the first dimension is simply a number from 0 to n. The second dimension is just some information about a user. What I want to do is I want to turn it into a 3D array, the first dimension of which can be 0 to n, but the second dimension has to be 0 to 2. The third dimension is still info about the user. Basically, I want to go from this:
to this:
I know I need to use some for loops, but for the life of me I can't figure out how. Sorry about such a newb question.
Thanks!
Code: Select all
searchresults Array=>
[0]=>Array
['username']=>evilmonkey
['picture'] => evil.jpg
[1]=>Array
['username']=>joeblow
['picture']=>joeblow.jpg
[2] => array
[username] => foobar
[pic] => foobar.jpg
[3] => array
[username] => bazfoo
[pic] => bazfoo.jpg
[3] => array
[username] => zoobar
[pic] => zoobar.jpgCode: Select all
results [0] => array
[0] => array
[username] => evilmonkey
[pic] => evil.jpg
[1] => array
[username] => joeblow
[pic] => joeblow.jpg
[2] => array
[username] => foobar
[pic] => foobar.jpg
[1] => array
[0] => array
[username] => bazfoo
[pic] => bazfoo.jpg
[1] => array
[username] => zoobar
[pic] => zoobar.jpgThanks!