Quick actions

cmd+k|ctrl+k

Navigation

Languages

test_readdir

Snippet info

Language

Php

Visibility

public

Author

fenghestudio

Created

2019-09-17T02:00:46Z

Updated

2019-09-17T02:00:46Z

<?php

// 注意在 4.0.0-RC2 之前不存在 !== 运算符
if ($handle = opendir('/path/to/files')) {
    echo "Directory handle: $handle\n";

    echo "Files:\n";

    /* 这是正确地遍历目录方法 */
    while (false !== ($file = readdir($handle))) {
        echo "$file\n";

    }
    /* 这是错误地遍历目录的方法 */
    while ($file = readdir($handle)) {
        echo "$file\n";

    }
    closedir($handle);

}
?>
INFO