What are the advantages of using array_push() over direct assignment when creating arrays in PHP for folder synchronization?

When creating arrays for folder synchronization in PHP, using array_push() allows for dynamic addition of elements to the array without needing to know the index of the next element. This can be particularly useful when iterating through folders and adding file paths to the array. Direct assignment, on the other hand, requires knowing the index of the next element and can be cumbersome when dealing with a large number of files.

// Using array_push() to add file paths to an array for folder synchronization
$files = array();
$directory = 'path/to/directory';

foreach (new DirectoryIterator($directory) as $fileInfo) {
    if ($fileInfo->isFile()) {
        array_push($files, $fileInfo->getPathname());
    }
}

print_r($files);