In PHP, zip_read() returns the next entry from an archive opened with zip_open(), one entry per call.
It is deprecated as of PHP 8.0. With ZipArchive, loop from 0 to numFiles, or call statIndex() until it returns false, to walk through every entry.
Syntax
Call zip_read() with the values you need. Start with this line.
PHP
// Deprecated (PHP 8.0+)
while ($entry = zip_read($zip)) {
echo zip_entry_name($entry), PHP_EOL;
}
// Modern equivalent
for ($i = 0; $i < $zip->numFiles; $i++) {
echo $zip->getNameIndex($i), PHP_EOL;
}
Call
What it does
zip_read($zip)
Deprecated: returns the next entry resource, or false when there are no more entries.
@zip_read($zip)
Deprecated: the @ operator hides the E_DEPRECATED notice only.
$zip->statIndex($i)
Modern ZipArchive: returns an array of details for the entry at that index, or false past the end.
zip_read() is deprecated in PHP 8.0. It moved an internal pointer forward each time you called it. ZipArchive uses plain numeric indexes, so you can read any entry in any order.
Library declarations
PHP
zip_read(resource $zip): resource|false
Parameters
Parameter
Description
zip
Required. The ZIP resource returned by zip_open().
Return Value
Return Value
Description
resource
A directory entry resource for the next entry.
false
There are no more entries, or an error happened.
PHP Examples
Example 1 — List Entries With a for Loop
Loop through every entry in a temp archive and print its name and size. The old while loop is a comment.