<?php
//无限遍历多维数组
$myarr=array("1",
"2",
array(
array("(a)","(b)"),
array("A","B","C"),
"(c)"),
"3",
array("a","b"));
function traverse_array(array $arr)
{
foreach($arr as $v)
{
if(is_array($v))
{
traverse_array($v);
}
else
{
echo $v."<br/>";
}
}
}
traverse_array($myarr);
?>
<?php
//计数器
$num=0;
if(!$f=fopen("num.txt", "r"))
{
echo "file inexsitent";
}
else
{
$num=fgets($f,10);
fclose($f);
}
$num++;
$ff=fopen("num.txt", w);
fwrite($ff, $num);
fclose($ff);
echo $num;
//输出图片计数器
$numarr=str_split($num);
foreach($numarr as $value)
{
echo "<img src='img/".$value.".jpg'>";
}
?>
<?php
//遍历文件夹
$path="f:\\php\\test_folder\\";
function traverse_dir($path)
{
$dir_array=scandir($path);
foreach($dir_array as $value)
{
if(is_dir($path.$value) && $value!="." &&$value!="..")
//unknown ".." & ".", so I drop them !
{
$current_path=$path.$value."\\";
echo $current_path."<br/>";
traverse_dir($current_path);
}
}
}
traverse_dir($path);
?>