1. <?php
  2. /**
  3. * Buffers CLI arguments for exploratory work.
  4. *
  5. * This script reads CLI arguments into an array, allowing for
  6. * optional flags and flexible processing.
  7. */
  8. /**
  9. * Function to buffer CLI arguments.
  10. *
  11. * @param array &$args The array to store the arguments. Passed by reference
  12. * to modify the original array.
  13. */
  14. function bufferArgs(&$args) {
  15. while ($argc > 1 && $argv[1] !== '--finish') {
  16. $args[] = $argv[1];
  17. $argc--;
  18. $argv--;
  19. }
  20. $args[] = 'finish'; // Signal end of argument parsing
  21. }
  22. // Get CLI arguments
  23. $args = [];
  24. $bufferArgs($args);
  25. // Process the buffered arguments
  26. if (!empty($args)) {
  27. echo "Buffered arguments:\n";
  28. print_r($args);
  29. // Example processing: Iterate through arguments
  30. foreach ($args as $arg) {
  31. echo "Processing arg: " . $arg . "\n";
  32. }
  33. } else {
  34. echo "No arguments provided.\n";
  35. }
  36. ?>

Add your comment