How would I create a function that would get a specific range of elements from a multidimensional nested array (example structure below)?

So for example, entering a range of 1-3 would return the first 3 elements in the array (1234, 1240, and 1352 according to the structure below). A range of 5-6 would return the 5th element up to the 6th element (1235 and 1272 according to the structure below).

I'm aware of `array_slice()`, however, that function doesn't work for my case without modification.

Here is an example structure of the array (varying depth).

```
Array
(
    [1234] => Array
        (
            [product_id] => 1234
            [parent_id] => 1220
            [children] => Array
                (
                    [1240] => Array
                        (
                            [post_id] => 1240
                            [parent_id] => 1234
                            [children] => Array
                                (
                                    [1352] => Array
                                        (
                                            [post_id] => 1352
                                            [parent_id] => 1240
                                            [children] => Array
                                                (
                                                )

                                        )

                                    [1568] => Array
                                        (
                                            [post_id] => 1568
                                            [parent_id] => 1240
                                            [children] => Array
                                                (
                                                )

                                        )

                                )

                        )

                )
         )

     [1235] => Array
         (
              [post_id] => 1235
              [parent_id] => 1220
              [children] => Array
                  (
                      [1272] => Array
                          (
                              [post_id] => 1272
                              [parent_id] => 1235
                              [children] => Array
                                  (
                                  )
                           )
                  )

         )
)

```