I currently have a parent-child model in my database. The table looks like this:

id int
parent_id int
text int

Assuming I've done the SELECT * query to retrieve all the columns on this table, how exactly would I go about building a multi-dimensional array from this result set, where each array contains an array of children where the parent_id is equal to the rows id.

Sample data:

id parent_id text
1 NULL Blah1
2 1 Blah 2
3 2 Blah3
4 1 Blah 4

Finally, once that array is built, how would you iterate through it to print out the tree like indented structure?