Hàm tua lại PHP ()
Ví dụ
Mở một thư mục, liệt kê các tệp của nó, đặt lại địa chỉ xử lý thư mục, liệt kê lại các tệp của nó, sau đó đóng:
<?php
$dir = "/images/";
// Open a directory, and read its contents
if (is_dir($dir)){
if ($dh = opendir($dir)){
// List files in images directory
while (($file = readdir($dh)) !== false){
echo "filename:" . $file . "<br>";
}
rewinddir();
// List once again files in images directory
while (($file = readdir($dh)) !== false){
echo "filename:" . $file . "<br>";
}
closedir($dh);
}
}
?>
Kết quả:
filename: cat.gif
filename: dog.gif
filename: horse.gif
filename: cat.gif
filename: dog.gif
filename: horse.gif
Định nghĩa và cách sử dụng
Hàm rewinddir() đặt lại phần xử lý thư mục được tạo bởi opendir() .
Cú pháp
rewinddir( dir )
Giá trị tham số
Parameter | Description |
---|---|
dir | Optional. Specifies the directory handle resource previously opened with opendir() . If this parameter is not specified, the last link opened by opendir() is assumed |
Chi tiết kỹ thuật
Giá trị trả về: | NULL nếu thành công, FALSE nếu thất bại |
---|---|
Phiên bản PHP: | 4.0+ |
❮ Tham chiếu thư mục PHP