<?php
/**
* Removes duplicate CLI arguments based on hard-coded limits.
*
* @param array $argv The command-line arguments.
* @param int $max_occurrences The maximum number of allowed occurrences of each argument.
* @return array The processed array of arguments with duplicates removed.
*/
function removeDuplicateArgs(array $argv, int $max_occurrences = 1): array
{
$counts = []; // Array to store argument counts
$result = []; // Array to store the processed arguments
foreach ($argv as $arg) {
if (!isset($counts[$arg])) {
$counts[$arg] = 0;
}
if ($counts[$arg] < $max_occurrences) {
$result[] = $arg;
$counts[$arg]++;
}
}
return $result;
}
// Example Usage (for testing)
if (count($argv) > 1) {
$processedArgs = removeDuplicateArgs($argv, 1); // Limit to 1 occurrence
print_r($processedArgs);
} else {
echo "No arguments provided.\n";
}
?>
Add your comment