Доброго времени суток.
Есть массив:
| Код | $tree = array( array('id' => 1, 'parent' => 0, 'user' => 'Nick', 'comment' => 'Really?'), array('id' => 2, 'parent' => 0, 'user' => 'Nick', 'comment' => 'How it can be?'), array('id' => 3, 'parent' => 2, 'user' => 'John', 'comment' => 'Simply, as it should be!'), array('id' => 4, 'parent' => 1, 'user' => 'John', 'comment' => 'Exactly!'), array('id' => 5, 'parent' => 3, 'user' => 'Nick', 'comment' => 'It\'s realy cool!'), );
|
Нужно получить массив в таком порядке:
| Код | $tree = array( // thread #1 array('id' => 1, 'parent' => 0, 'user' => 'Nick', 'comment' => 'Really?'), array('id' => 4, 'parent' => 1, 'user' => 'John', 'comment' => 'Exactly!'), // thread #2 array('id' => 2, 'parent' => 0, 'user' => 'Nick', 'comment' => 'How it can be?'), array('id' => 3, 'parent' => 2, 'user' => 'John', 'comment' => 'Simply, as it should be!'), array('id' => 5, 'parent' => 3, 'user' => 'Nick', 'comment' => 'It\'s realy cool!'), );
|
То есть отсортировать по ключам parent и id так, чтобы получить ветки комментариев. Никак не могу составить usort функцию. |