Page 1 of 1

php to write code for it self depending on the input....

Posted: Mon Apr 11, 2005 10:46 am
by Calimero
This little :twisted: :twisted: :twisted: baby, ehm !

Gave me "little" problems, did it any possible way I could think of, but couldn't find a solution.

Here it goes: :arrow:

Is there a way for php to create the following

multi-dimensional array, but how deep ( how many [][][][] ) are calculated on the input parameters ( 10 - will give ten-levels deep )

it is very easy for 2 levels - two FOR loops and finished, but - I don't think that my machine would react positively on lets say 20 FOR in FOR loops or how ever many user inputs.

So is there any easier way to do this.


Any ideas would be very helpful !

Posted: Mon Apr 11, 2005 10:55 am
by timvw
why don't you give it a try first? i would be surprised if looking up 10 indices would ask that much significant cpu cycles...

otherwise, you can create an array with 1 dimension.

and calculate yourself where [$i][$j] is.

because, it's the same as ($i * sizeof dim1) + $j

and [$i][$j][k$] is the same as ($i * sizeof dim1) + ($j * sizeof dim2) + $k

and so on...