Hàm rewinddir () trong PHP
Thí dụ
Mở một thư mục, liệt kê các tệp của nó, đặt lại trình điều khiển thư mục, liệt kê các tệp của nó một lần nữa, 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 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ả lại: | NULL khi thành công, FALSE khi thất bại |
---|---|
Phiên bản PHP: | 4.0+ |
❮ Tham chiếu thư mục PHP