How can PHP be used to create an associative array mapping old numbers to new numbers for efficient file renaming operations?
When renaming files in bulk, it's often necessary to keep track of the old and new filenames. One efficient way to do this is by using an associative array in PHP that maps old filenames to new filenames. This allows for easy lookup and retrieval of the new filename when needed during the renaming process.
<?php
// Define an associative array to map old filenames to new filenames
$fileMapping = array(
"old_file1.txt" => "new_file1.txt",
"old_file2.txt" => "new_file2.txt",
"old_file3.txt" => "new_file3.txt"
);
// Example usage: retrieve the new filename for "old_file2.txt"
$oldFilename = "old_file2.txt";
$newFilename = $fileMapping[$oldFilename];
echo "New filename for $oldFilename is $newFilename";
?>