Home >Backend Development >PHP Tutorial >php array breadth traversal php7 php environment construction php from entry to proficiency

php array breadth traversal php7 php environment construction php from entry to proficiency

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOriginal
2016-07-29 08:54:14997browse

//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.

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn