Solved

Recursive Arrays

Posted on 2007-03-17
2
525 Views
Last Modified: 2013-12-13
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
Comment
Question by:pagemastah
2 Comments
 
LVL 49

Accepted Solution

by:
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

by:JoseParrot
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

VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

Question has a verified solution.

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

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…

773 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question