简体   繁体   中英

how to create an array in an array in an array in with 3 foreachs php

I want to make sure that I can get 3 steps from my database. My array should then look like this with 3 foreachs in each other:

user1
   user2
     user6
     user7
user2
   user3
     user7
   user4
     user8
     user9
user3
   user5
     user10
     user11
     user12

Please, correct me if I'm wrong, but it seems that you want something like this:

foreach ($input as $k1 => $v1) {
    foreach ($v1 as $k2 => $v2) {
        foreach ($v2 as $k3 => $v3) {
            //Do something
        }
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM