Recursive Arrays

Posted on 2007-03-17
Medium Priority
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:


should produce:

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

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

Accepted Solution

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

LVL 18

Expert Comment

by:Jose Parrot
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.


Featured Post

Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

This article discusses four methods for overlaying images in a container on a web page
Article by: evilrix
Looking for a way to avoid searching through large data sets for data that doesn't exist? A Bloom Filter might be what you need. This data structure is a probabilistic filter that allows you to avoid unnecessary searches when you know the data defin…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

619 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