What is the appropriate way to set file permissions using the chmod() function in PHP?

When setting file permissions using the chmod() function in PHP, it is important to understand the octal representation of permissions. Each digit in the octal representation corresponds to a specific user group (owner, group, others) and the permissions they have (read, write, execute). To set appropriate permissions, you need to calculate the sum of the desired permissions for each user group and pass it as an argument to the chmod() function.

// Set file permissions to read, write, execute for owner, read and execute for group and others
chmod("example.txt", 0755);