PHP 8.5.0 RC 2 available for testing

rewinddir

(PHP 4, PHP 5, PHP 7, PHP 8)

rewinddir β€” Retorna al primer elemento del directorio

DescripciΓ³n

rewinddir(?resource $dir_handle = null): void

rewinddir() retorna al primer elemento del directorio identificado por dir_handle.

ParΓ‘metros

dir_handle

El resource de directorio abierto previamente con opendir(). Si no se proporciona el recurso de directorio, se utilizarΓ‘ el ΓΊltimo recurso abierto con la funciΓ³n opendir().

Valores devueltos

No se retorna ningΓΊn valor.

Historial de cambios

VersiΓ³n DescripciΓ³n
8.0.0 context ahora es nulo.
οΌ‹add a note

User Contributed Notes 2 notes

up
7
osamahussain897 at gmail dot com ΒΆ
7 years ago
/* Source Code */

<?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);
}
}
?>

/* Result */

filename: cat.gif
filename: dog.gif
filename: horse.gif
filename: cat.gif
filename: dog.gif
filename: horse.gif
up
6
ASchmidt at Anamera dot net ΒΆ
7 years ago
It is crucial to note that rewinddir() does not simply start over at the beginning of the SAME directory list. Instead, this function first re-reads the directory - thus any file that were deleted (or inserted) since the original opendir() will be reflected after "rewinding".

In that respect, rewinddir() is equivalent to a closedir(), opendir() sequence, but without obtaining a new handle.
To Top