How can the umask function be used to modify directory permissions in PHP?

The umask function in PHP can be used to modify directory permissions by setting the default permissions that will be applied when creating new directories. By changing the umask value, you can control the permissions that are automatically set for newly created directories in your PHP script.

// Set a new umask value to modify directory permissions
$old_umask = umask(0); // Set umask to 0 to allow full permissions
mkdir("/path/to/directory", 0777); // Create a new directory with permissions set to 0777
umask($old_umask); // Reset the umask value to its original state