我有一个数组来构建组织结构图。
Array
(
[23669852747] => Array
(
[500] => Array
(
[2491972948] => Array
(
[1231166368] => TH
[9490413968] => JDA
[12870445747] => MA
[12977638248] => VA3
[17780619828] => TW
)
[14878692388] => Array
(
[5013958588] => GR
[5565058248] => RW
[9490304728] => KT
[14878677648] => DB
[17700259647] => KM
)
)
)
[1113153218] => Array
(
[23669852747] => Array
(
[500] => Array
(
[1271769097] => KVG
[4077135657] => JS
[4084656658] => TB
[6222434168] => MS
[7791194248] => JH
[14776063607] => Jh
[14776070467] => Kh
[14878692388] => Rn
)
[23761746408] => Array
(
[2510729147] => DD
[5007359557] => HF
[9490374108] => JJ
[12870445287] => KT
[12977588048] => EJ
)
)
[1310250127] => Array
(
[2510739127] => Array
(
[2510754677] => JC
[5013973888] => Jl
[6191488947] => Gl
)
[2510806547] => Array
(
[4077190247] => TSA
[4084643158] => KS
[5562275597] => JE
[5562365547] => BBH
[12870264027] => AM
)
[2510774837] => Array
(
[4077214557] => CS
[5013992688] => SW
[5562213897] => JC
[5565089238] => DH
)
[55] => Array
(
[5007299037] => IF
[6191533887] => JB
)
)
)
)
23669852747和1310250127都报告给1113153218 我用这段代码来识别这个人
if(sizeof($team_array) > 1)
{
$array_keys = array_keys($team_array);
foreach($team_array as $dir_id=>$dir_group)
{
for($a=0;$a<sizeof($array_keys); $a++)
{
$temp_dir = $array_keys[$a];
if(isset($team_array[$dir_id][$temp_dir])) $sr_dir = $dir_id;
}
}
}
我试图将所有人推到1113153218
[1113153218] => Array
(
[23669852747] => Array
(
[500] => Array
(
[1271769097] => KVG
[4077135657] => JS
[4084656658] => TB
[6222434168] => MS
[7791194248] => JH
[14776063607] => Jh
[14776070467] => Kh
[14878692388] => Array
(
[5013958588] => GR
[5565058248] => RW
[9490304728] => KT
[14878677648] => DB
[17700259647] => KM
)
[2491972948] => Array
(
[1231166368] => TH
[9490413968] => JDA
[12870445747] => MA
[12977638248] => VA3
[17780619828] => TW
)
)
[23761746408] => Array
(
[2510729147] => DD
[5007359557] => HF
[9490374108] => JJ
[12870445287] => KT
[12977588048] => EJ
)
[14878692388] => Array
(
[5013958588] => GR
[5565058248] => RW
[9490304728] => KT
[14878677648] => DB
[17700259647] => KM
)
)
[1310250127] => Array
(
[2510739127] => Array
(
[2510754677] => JC
[5013973888] => Jl
[6191488947] => Gl
)
[2510806547] => Array
(
[4077190247] => TSA
[4084643158] => KS
[5562275597] => JE
[5562365547] => BBH
[12870264027] => AM
)
[2510774837] => Array
(
[4077214557] => CS
[5013992688] => SW
[5562213897] => JC
[5565089238] => DH
)
[55] => Array
(
[5007299037] => IF
[6191533887] => JB
)
)
)
使用此代码:
$new_team_array[$sr_dir]=$team_array[$sr_dir];
foreach($team_array as $dir_id=>$dir_group)
{
if($dir_id != $sr_dir) {
foreach($dir_group as $mgr_id=>$mgr_group)
{
$new_team_array[$sr_dir][$dir_id][$mgr_id] = $mgr_group;
}
}
}
当我合并它们时,我失去了一些关联,例如23761746408在原来有5个直接报告,加上另一对100个人(省略)合并后5个直接报告丢失并且当两个100人数组已添加。
我想在所有子数组中循环以单独添加它们,但希望有一种更简单的方法,因为我必须检查数组深度。
我尝试使用array_merge但丢失了密钥关联