PHP ZipArchive count() Function Last Updated : 25 Jul, 2024 Comments Improve Suggest changes Like Article Like Report The ZipArchive::count() function is an inbuilt function in PHP that is used to count the number of files in a zip archive.Syntax:int ZipArchive::count()Parameters: This function does not accept any parameters.Return Value:This function returns the number of files in the zip archive.Example 1: The following code demonstrates the total count of a zip file. PHP <?php // Create a new ZipArchive object $zip = new ZipArchive; // Check for opening the zip file if ($zip->open('Geeks.zip')) { // If zip file is open then add an // empty directory "GeeksforGeeks" if($zip->addEmptyDir('GeeksforGeeks')); echo 'Total files/directory: ' . $zip->count(); // Close the zip file $zip->close(); } // If zip file is not open/exist else { echo 'Failed to open zip file'; } ?> Output:Example 2: The following code shows the total number of files after adding the extra 3 files as given in the code. PHP <?php // Create a new ZipArchive object $zip = new ZipArchive; // Check for opening the zip file if ($zip->open('Geeks.zip', ZipArchive::CREATE)) { echo 'Total number of files: ' . $zip->count() . '<br>'; // Create new txt file and // add String to the file $zip->addFromString( 'GFG1.txt', 'Welcome to GeeksforGeeks' ); $zip->addFromString( 'GFG2.txt', 'A computer science portal' ); $zip->addFromString( 'GFG3.txt', 'Welcome to GeeksforGeeks' ); echo 'Total files after adding new files: ' . $zip->count(); // Close the zip file $zip->close(); } // If zip file is not open/exist else { echo 'Failed to open zip file'; } ?> Output:Reference: https://www.php.net/manual/en/ziparchive.count.php Comment More infoAdvertise with us Next Article PHP ZipArchive count() Function V vkash8574 Follow Improve Article Tags : Web Technologies PHP PHP-function Similar Reads PHP | SplHeap count() Function The SplHeap::count() function is an inbuilt function in PHP which is used to count the elements in the heap. Generally, Heap can be of two types: Max-Heap: In a Max-Heap the key present at the root node must be greatest among the keys present at all of its children. The same property must be recursi 2 min read PHP count() Function The count() function in PHP is used to count the number of elements in an array or the countable properties of an object. The function returns an integer value representing the number of items present.Syntax:count($array, mode)In this syntax:$array (mandatory): Refers to the array, whose elements ar 3 min read PHP substr_count() Function The substr_count() is a built-in function in PHP and is used to count the number of times a substring occurs in a given string. The function also provides us with an option to search for the given substring in a given range of the index. It is case sensitive, i.e., "abc" substring is not present in 3 min read PHP SplFixedArray count() Function The SplFixedArray::count() function is an inbuilt function in PHP which is used to return the size of the array. Syntax: int SplFixedArray::count() Parameters: This function does not accept any parameter. Return Value: This function returns the size of the array. Below programs illustrate the SplFix 1 min read PHP SplPriorityQueue count() Function The SplPriorityQueue::count() function is an inbuilt function in PHP which is used to count the number of elements in the queue. Syntax: int SplPriorityQueue::count() Parameters: This function does not accept any parameters. Return Value: This function returns the number of elements in the queue. Ex 1 min read Like