PHP Novice to ask you a question, has now been captured from the database by recursion all subordinates of an employee (including subordinate subordinates), Print_r ($sub) effect is as follows:
Array ([0] = User Object ([userId] = 365 [name] = AA [Cn_name] =&G T Wang a [job] + a regional sales engineer [rep_id] = 368 [Sub] = = Array ( )) [1] = = User Object ([userId] = 367 [name] + cc [cn_n AME] + Wang C [job] + a regional sales Director [REP_ID] = 368 [Sub] + = Array ( [0] = = User Object ([userId] = 379 [Name] = + mm [Cn_name] = yellow xx [job] + sales Project Division [REP_ID] = 367 [Sub] = = Array ([0] = = User Object ( [UserId] = 381 [name] = ABC [Cn_name] = Zhang ABC [job] and sales engineer [rep_id] = 379 [Sub] = = Array ( ) ) )) [1] = = User Object ( [UserId] = 380 [name] + xxxx [cn_name] = x [Job] = Sales Engineer [rep_id] = 367 [Sub] = = Array ())) ))
The need now is to write a function, traverse the multi-series group, and then generate a new one-dimensional array, similar to this:
Array ([0] = User Object ([userId] = 365 [name] = AA [Cn_name] =&G T Wang a [job] + a regional sales engineer [rep_id] = 368) [1] = = User Object ([US Erid] = 367 [name] + cc [Cn_name] + Wang C [job] + a regional sales director [REP_ID ] = = 368) [2] = = User Object ([userId] = 379 [Name] = = mm [Cn_name] = yellow xx [job] = Sales Engineer [rep_id] = 367) [3] = = User Object ( [UserId] = 381 [name] + ABC [cn_name]--Zhang ABC [job]--Sales Engineer [rep_id] = 379) [4] = = User Object ([userId] = 380 [name] =&G T xxxx [Cn_name] = Zhang xx [job] = Sales Engineer [rep_id] + 367))
Feel this is the basic application of the array, but the brain short-circuiting, half a day did not get out, so ask you, I hope you great God enlighten, humbly!
Reply to discussion (solution)
Have you been out of work for the holidays? The bitter force also has to work overtime.
Read with foreach (xxx as Key=>value), and the new array is assigned a value.
Read with foreach (xxx as Key=>value), and the new array is assigned a value.
This can only be read to the first level of elements, the second level will be lost.
Recursive generation, of course, also to hand their oaths dimension
Recursive generation, of course, also to hand their oaths dimension
Well, yes, we're going to have to use recursion and global variables.