0

Well, not sure I am going to be able to write this out to well, but I will try. From a backend script I can't really change up to much. I have a very large multi-dimensional array being spit out to the UI where the array's within the main array dont contain your normal 0-n index scheme, and they are generated off the backend due to the association they have. So I have for example a piece of the multi-dimensional array that looks like

Array(
     [0] = Array(
               [stuff] = 'something'
               [morestuff] = 'other'
               [info] = array(
                               [generated_id_based_on_assication] = array(
                                                              [id] = '12345t'
                                                              [desc] = 'blah blah'
                                                              [url] = '/some/where'
                                                              )
                               [generated_id_based_on_assication] = array(
                                                              [id] = '12345t'
                                                              [desc] = 'blah blah'
                                                              [url] = '/some/where'
                                                              )
                               [generated_id_based_on_assication] = array(
                                                              [id] = '12345t'
                                                              [desc] = 'blah blah'
                                                              [url] = '/some/where'
                                                              )
                               [generated_id_based_on_assication] = array(
                                                              [id] = '12345t'
                                                              [desc] = 'blah blah'
                                                              [url] = '/some/where'
                                                              )
                        )
              ),
     [1] = Array(
               [stuff] = 'something'
               [morestuff] = 'other'
               [info] = array(
                               [generated_id_based_on_assication] = array(
                                                              [id] = '12345t'
                                                              [desc] = 'blah blah'
                                                              [url] = '/some/where'
                                                              )
                               [generated_id_based_on_assication] = array(
                                                              [id] = '12345t'
                                                              [desc] = 'blah blah'
                                                              [url] = '/some/where'
                                                              )
                               [generated_id_based_on_assication] = array(
                                                              [id] = '12345t'
                                                              [desc] = 'blah blah'
                                                              [url] = '/some/where'
                                                              )
                               [generated_id_based_on_assication] = array(
                                                              [id] = '12345t'
                                                              [desc] = 'blah blah'
                                                              [url] = '/some/where'
                                                              )
                        )
              )
       )

I know not the best representation of an array. But for the sake of example as I can't post the actual data itself what I need to do is for the [info] array find each generated_id_based_on_assication so I can pull data from each generated_id_based_on_assication array. But seeing as its not a 0-n index Im not sure how to grab that "generated_id_based_on_assication" part so I can work with the data within it, as running it through a foreach or any type of loop really isn't an option for that particular array within the arrays. Anyone have a suggestion? If I was able to run this through a loop I could do it, but thats where im tripped up I can't as this data is being listed in tables, and everything is on a per row basis for that array.

1 Answer 1

2

Assuming your outer array is in a variable called $array.. Try

$keys = array_keys($array[0]['info']);

and then $keys will contain the generated ids and you can use them like this

$desc = $array[0]['info'][$keys[0]]['desc'];

http://php.net/manual/en/function.array-keys.php

Sign up to request clarification or add additional context in comments.

1 Comment

That may just do exactly what I am looking for, thank you, gonna give that a shot right now.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.