Home >Backend Development >PHP Tutorial >php array breadth traversal php7 php environment construction php from entry to proficiency
//Array breadth traversal
function testFunc($array){
$arr = array();
foreach ($array as $value) {
if (is_array($value)) {
$arr[ ] = $value;
} else {
echo $value."
";
}
}
if (!empty($arr)) {
while ($temp = current($arr)) {
foreach ($temp as $val){
if (is_array($val)) {
$arr[] = $val;
} else {
echo $val."
";
}
}
unset($arr[key($arr)]);
}
}
}
//Start test data
$testarr = array(
1,
array(
6,
array(
16,
17,
18
),
8,
9,
array(
19,
array(
25,
26,
27
)
)
),
3,
4,
array(
11,
array(
21,
22,
23
),
13,
14,
array(
24,
array(
28,
29,
30
)
)
)
);
testFunc($testarr );
?>
The above introduces PHP array breadth traversal, including PHP content. I hope it will be helpful to friends who are interested in PHP tutorials.