PHP rewinddir()ฟังก์ชั่น
ตัวอย่าง
เปิดไดเร็กทอรี แสดงรายการไฟล์ รีเซ็ตหมายเลขอ้างอิงของไดเร็กทอรี แสดงรายการไฟล์อีกครั้ง จากนั้นปิด:
<?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);
}
}
?>
ผลลัพธ์:
filename: cat.gif
filename: dog.gif
filename: horse.gif
filename: cat.gif
filename: dog.gif
filename: horse.gif
ความหมายและการใช้งาน
ฟังก์ชัน rewinddir() รีเซ็ตหมายเลขอ้างอิงไดเรกทอรีที่สร้างโดยopendir( )
ไวยากรณ์
rewinddir(dir)
ค่าพารามิเตอร์
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 |
รายละเอียดทางเทคนิค
คืนมูลค่า: | NULL กับความสำเร็จ FALSE เมื่อล้มเหลว |
---|---|
รุ่น PHP: | 4.0+ |
❮ การอ้างอิงไดเรกทอรี PHP