Solved

Recursive Arrays

Posted on 2007-03-17
2
520 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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Time difference 10 36
Converting SQL server date to string 3 17
url rewrites not working in codeigniter 2 13
PHP JSON Clean up 5 10
Article by: Nadia
Suppose you use Uber application as a rider and you request a ride to go from one place to another. Your driver just arrived at the parking lot of your place. The only thing you know about the ride is the license plate number. How do you find your U…
Article by: Nadia
Linear search (searching each index in an array one by one) works almost everywhere but it is not optimal in many cases. Let's assume, we have a book which has 42949672960 pages. We also have a table of contents. Now we want to read the content on p…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to count occurrences of each item in an array.

743 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now