# Get all elements of a multidimensional array

**URL:** <https://forum.kirupa.com/t/get-all-elements-of-a-multidimensional-array/329765>\
**Category:** flash\
**Created:** [October 12, 2012, 6:07pm UTC](https://forum.kirupa.com/t/get-all-elements-of-a-multidimensional-array/329765 "2012-10-12T18:07:17Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![tpann](https://avatars.discourse-cdn.com/v4/letter/t/c67d28/32.png) [@tpann](https://forum.kirupa.com/u/tpann)\
**Post date:** [October 12, 2012, 6:07pm UTC](https://forum.kirupa.com/t/get-all-elements-of-a-multidimensional-array/329765/1 "2012-10-12T18:07:17Z")

</div>

I am looking for a way of returning a multidimensional array as a non-multidimensional array, as in converting this:

a:Array = [obj1, [obj2, [obj3, [obj4, [obj5, obj6]]]]]

to a “flat” array, like this:

```php
var b:Array = foobar(a);
trace(b); // obj1,obj2,obj3,obj4,obj5,obj6
function foobar(arr:Array):Array {
     // what do I do with a?
}

```

Here a.length = 2, since it contains an object and an array, and b.length = 6. For my application, I need a function that will determine b for any dimensional depth of a. Because at some point the innermost array in a will change from [obj5,obj6] to [obj5,[obj6,obj7]]. Once this happens, of course a.length will still be 2 but b.length would be 7.

I have a feeling this involves a while or do while loop, but my brain has some type of aversion to those and I don’t seem to be able to ever formulate such a loop successfully.

Any help? Thanks!
