时间:2021-07-01 10:21:17 帮助过:5人阅读
$a = array(array (
1 => 7,
7 => 11,
8 => 7,
9 => 8,
10 => 11,
11 => 12,
12 => NULL,
);
$i = 1;
while(isset($a[$i])) {
$r[$i] = $a[$i];
$i = $a[$i];
}
$r[$i] = $a[$i];
var_export($r);
$map = array(
1 => 7,
7 => 11,
8 => 7,
9 => 8,
10 => 11,
11 => 12,
12 => NULL
);
function getroad($map){
$key = 1;
$result = array();
while($key!=NULL){
$result[$key] = $map[$key];
$key = $map[$key];
}
return $result;
}
$result = getroad($map);
var_export($result);