Solved

Recursive Arrays

Posted on 2007-03-17
2
529 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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: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.

Jose
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
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…
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…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

738 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