I
I
Ivan2015-02-17 18:55:03
PHP
Ivan, 2015-02-17 18:55:03

How to convert an array by one of the values?

There is an array obtained from SQL, looks something like this:

[0] => Array
        (
            [0] => 357
            [1] => Трапезная палата
            [2] => 350
        )

    [1] => Array
        (
            [0] => 355
            [1] => Монашеская келья
            [2] => 354
        )

    [2] => Array
        (
            [0] => 358
            [1] => Успенский собор (интерьеры, иконостас, росписи) 
            [2] => 350
        )

    [3] => Array
        (
            [0] => 351
            [1] =>паперть собора Рождества Богородицы
            [2] => 354
        )

    [4] => Array
        (
            [0] => 359
            [1] => Архимандричьи кельи 
            [2] => 350
        )
)

Accordingly, the parameter [2] is the id of the parent, and you need to display the list like this:
[350] => Array
       (
            [0] => Трапезная палата
            [1] => Архимандричьи кельи 
        )

[354] => Array
       (
            [0] => паперть собора Рождества Богородицы
            [1] => Монашеская келья
        )

I'm sure there are similar examples on the net, but I can't figure out how to properly ask Google.
PS
Do not pay attention to the text of the example, I'm picking someone else's code of the monastery site.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
DevMan, 2015-02-17
@LiguidCool

Bypass the array and collect such as needed.
What is the problem?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question