What is the purpose of incrementing variables like $g1, $g2, and $g3 in PHP when sorting file names into arrays?

When sorting file names into arrays in PHP, incrementing variables like $g1, $g2, and $g3 can be useful for dynamically creating unique keys for each file. This allows us to easily sort and organize the files based on specific criteria, such as file name or file size. By incrementing these variables, we can ensure that each file is assigned a distinct key in the array, preventing any potential conflicts or overwriting of data.

$files = glob('path/to/files/*');
sort($files);

$sortedFiles = array();

$g = 1;
foreach ($files as $file) {
    $sortedFiles['g' . $g] = $file;
    $g++;
}

print_r($sortedFiles);