Rumah > Artikel > pembangunan bahagian belakang > 多级数组遍历问题
PHP新手请教各位一个问题,现已通过递归从数据库中抓出来一个员工的所有下属(包括下属的下属),print_r ($sub)效果如下:
Array( [0] => User Object ( [userId] => 365 [name] => aa [cn_name] => 王A [job] => A区域销售工程师 [rep_id] => 368 [sub] => Array ( ) ) [1] => User Object ( [userId] => 367 [name] => cc [cn_name] => 王C [job] => A区域销售主管 [rep_id] => 368 [sub] => Array ( [0] => User Object ( [userId] => 379 [name] => mm [cn_name] => 黄XX [job] => 销售工程师 [rep_id] => 367 [sub] => Array ( [0] => User Object ( [userId] => 381 [name] => abc [cn_name] => 张abc [job] => 销售工程师 [rep_id] => 379 [sub] => Array ( ) ) ) ) [1] => User Object ( [userId] => 380 [name] => xxxx [cn_name] => 张XX [job] => 销售工程师 [rep_id] => 367 [sub] => Array ( ) ) ) ))
Array( [0] => User Object ( [userId] => 365 [name] => aa [cn_name] => 王A [job] => A区域销售工程师 [rep_id] => 368 ) [1] => User Object ( [userId] => 367 [name] => cc [cn_name] => 王C [job] => A区域销售主管 [rep_id] => 368 ) [2] => User Object ( [userId] => 379 [name] => mm [cn_name] => 黄XX [job] => 销售工程师 [rep_id] => 367 ) [3] => User Object ( [userId] => 381 [name] => abc [cn_name] => 张abc [job] => 销售工程师 [rep_id] => 379 ) [4] => User Object ( [userId] => 380 [name] => xxxx [cn_name] => 张XX [job] => 销售工程师 [rep_id] => 367 ))
都下班过节去了么?苦逼的还要加班。。
用foreach(xxx as key=>value)读,新的数组赋值。
用foreach(xxx as key=>value)读,新的数组赋值。
递归产生的,当然也要递归降维
递归产生的,当然也要递归降维