S
S
sincopa2018-05-24 20:32:28
PHP
sincopa, 2018-05-24 20:32:28

Find parent section and write it to an array?

There is a Subdivision table where there are SubID and ParentID, and there is a Video table where there is a Select. In Select, SubIDs are written (406,407,469 - as an example). As a result, using Select, I need to find all SubIDs in the Subdivision table and display their ParentID parents, merge all repeated ParentIDs, display only unique ones.
The video array looks like this

Array ( 
    [0] => Array (
        [name] => Название 1 
        [select] => Array (
            [0] => 406
            [1] => 407
            [5] => 469
        )
    )
    [1] => Array ( 
        [name] => Название 2 
        [select] => Array (
            [0] => 390
            [1] => 396
            [2] => 469
        )
    )
)

It turns out, for example, for section
406, 407 - parent 1000
469 - parent 1001
390, 369 - parent 1002
The result should be such an array
Array ( 
    [0] => Array (
        [name] => Название 1 
        [parent_id] => Array (
            [0] => 1000
            [1] => 1001
        )
    )
    [1] => Array ( 
        [name] => Название 2 
        [parent_id] => Array (
            [0] => 1002
            [1] => 1001
        )
    )
)

No matter how much I try, it doesn't work. Or tell me in which direction to dig at least.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question