Solved

# Recursive Arrays

Posted on 2007-03-17
525 Views
Can anyone make a simple recursive function that puts arrays inside arrays?

The goal of the function is to make an array of arrays:

For example the function:

recurse(7);

should produce:

\$tree = array(array(array(array(array(array(array()))))));

I am going to use this for conforming with the Tree data structure.
0
Question by:pagemastah

LVL 49

Accepted Solution

Roonaan earned 500 total points
ID: 18740295
function recurseArray(\$depth) {
if(\$depth <=1) {
return array();
}
return array(recurseArray(\$depth -1));
}

-r-
0

LVL 18

Expert Comment

ID: 18742850
Pay attention to the amount of required memory.
If the array are of Integers (4 bytes each) and each array size is 10 then you need 4 x 10 power 7 bytes. Say, 38MB. But if its size is 100, then you need something like 380 Terabytes.

Jose
0

## Featured Post

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

### Suggested Solutions

Build an array called \$myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
This article discusses four methods for overlaying images in a container on a web page
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…