What is the purpose of the chown() function in PHP and how can it be used to change user ownership of directories?

The chown() function in PHP is used to change the user ownership of a file or directory. This can be useful when you need to change the owner of a directory for security or permission reasons. To change the user ownership of a directory using chown(), you need to provide the path to the directory and the new owner's user ID.

<?php
$directory = '/path/to/directory';
$newOwner = 'newuser';
chown($directory, $newOwner);
?>