开发者

php arrays create parenthood array

I have two arrays:

Parents:

Array
(
    [0] => Levi Self
    [2] => Portraits
    [3] => Abstract
)

Children:

Array
(
    [0] 开发者_开发问答=> Portraits
    [1] => Abstract
    [2] => Megan
    [3] => Locks
)

And I'm trying to build an array that looks like this:

Array
(
    [Levi Self] => Array
      (
          [0] => Portraits
          [1] => Abstract
      )

    [Portraits] => Array
      (
          [0] => Megan
      )

     [Abstract] => Array
      (
          [0] => Locks
      )
)

I am getting the hierarchy from the database table that looks like this:

Array
(
    [0] => Array
        (
            [title] => Portraits
            [parent] => Levi Self
        )

    [1] => Array
        (
            [title] => Abstract
            [parent] => Levi Self
        )

    [2] => Array
        (
            [title] => Megan
            [parent] => Portraits
        )

    [3] => Array
        (
            [title] => Locks
            [parent] => Abstract
        )

)

Am I trying something that is impossible? Thanks, Levi Self


foreach ($that_last_array_of_yours as $arr) {
  $result[$arr['parent']][] = $arr['title'];
}

print_r($result);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜