Home > Backend Development > PHP Tutorial > 请教一下这两段readdir循环的代码为什么会不一样呢

请教一下这两段readdir循环的代码为什么会不一样呢

WBOY
Release: 2016-06-13 12:09:30
Original
1017 people have browsed it

请问一下这两段readdir循环的代码为什么会不一样呢?
前面一段只能取得一部分文件
$han2 = opendir('dir');
while ( readdir($han2) !== false) {
echo readdir($han2);
echo "
";
}
closedir($han2);

这一段可以取得全部文件
$od = opendir('dir');
while (($readd = readdir($od)) !== false) {
echo $readd;
echo "
";
}
closedir($od);
------解决思路----------------------
dir中有a b c三个文件。前面一段while ( readdir($han2) !== false)运行完只会游标移到 a后面了,你在运行echo readdir($han2)只会读取到b。而后面一段 用变量接收,完全可以避免这个问题。

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template