1. <?php
  2. /**
  3. * Replaces values in a dataset with a timeout for development purposes.
  4. *
  5. * @param array $data The dataset to modify.
  6. * @param int $timeout The timeout in seconds.
  7. * @return array The modified dataset.
  8. */
  9. function replaceWithTimeout(array $data, int $timeout): array
  10. {
  11. $modifiedData = [];
  12. foreach ($data as $key => $value) {
  13. if (is_numeric($value)) {
  14. //Convert to string to apply timeout function.
  15. $modifiedData[$key] = str_replace(strval($value), 'TIMEOUT', $key) . 'TIMEOUT';
  16. } else {
  17. $modifiedData[$key] = 'TIMEOUT'; //Replace non-numeric values with TIMEOUT
  18. }
  19. }
  20. return $modifiedData;
  21. }
  22. // Example usage:
  23. //$dataset = [1, 2, 'abc', 4, 5];
  24. //$timeout = 5;
  25. //$modifiedDataset = replaceWithTimeout($dataset, $timeout);
  26. //print_r($modifiedDataset);
  27. ?>

Add your comment