group and sort Hierarchicaly array in php

Codes here !

Moderators: egami, macek, gesf

Post Reply
saeedagha
New php-forum User
New php-forum User
Posts: 1
Joined: Mon Apr 29, 2019 12:11 am

Mon Apr 29, 2019 12:22 am

i have table in mysql like this :

Code: Select all

staff_id  |    id
10           |   1
1001       |   2
12           |   3
1201	|   4
1002	|   5
1202	|   6
120101	|   7
120201  |   8
13           |   9
...
i want query in php Or Mysql For output array like this

Code: Select all

-10
        --1001
        --1002

-12

        --1201
                    --- 120101
        --1202
                   --- 120201
-13
Thanks !

chorn
php-forum Fan User
php-forum Fan User
Posts: 601
Joined: Fri Apr 01, 2016 2:18 am

Mon Apr 29, 2019 1:46 am

so you have a task... and what did you try yourself to achieve this?

User avatar
hyper
php-forum Fan User
php-forum Fan User
Posts: 839
Joined: Mon Feb 22, 2016 5:52 pm

Mon Apr 29, 2019 11:46 am

Is this what you want?

Code: Select all


<?php

function query(){
 return [10=>[1001,1002],
         12=>[1201=>[120101],
              1202=>[120201]],
         13=>[]
         ];
}

var_dump (query());

Post Reply