PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
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:
No no. I want to keep the values of the original array, but add another dimension to the front. This of it this way:
I have:
$var[0]='foo', $var[1]='bar', $var[2]='foobar', $var[3]='baz', $var[4]='foobaz'] and so on
and I want to convert it to:
$var[0][0]='foo', $var[0][1]='bar', $var[0][2]='foobar', $var[1][0]='baz', $var[1][1]='foobaz' and so on
I know the structure of a for loop (I've been doign PHP for a number of years)...this is just a case of mental block...can you tell what you mean by "adds 4 numbers ([x][0] to [x][3]) and then increment x by 1."?
Since you know you need to do some iteration here, just create a function for this. Within the function create a new array and populate with the rearragened elements of the old. Once you are finished, return it. Shuffling the items in the existing array isn't worth the effort.