What is the best way to switch between different folders in a PHP script while ensuring the ability to return back?

When switching between different folders in a PHP script, it is important to keep track of the current directory so that you can easily return back to it. One way to achieve this is by using the `chdir()` function to change the directory and storing the current directory in a variable before making the switch. This way, you can easily switch between folders and return back by using the stored directory path.

// Store the current directory
$currentDirectory = getcwd();

// Switch to a different folder
chdir('/path/to/another/folder');

// Perform operations in the new folder

// Return back to the original folder
chdir($currentDirectory);