1. <?php
  2. /**
  3. * Strips metadata from form field data.
  4. *
  5. * @param array $data An associative array of form field data.
  6. * @return array Stripped data.
  7. */
  8. function stripMetadata(array $data): array
  9. {
  10. $strippedData = [];
  11. foreach ($data as $key => $value) {
  12. // Remove metadata keys (e.g., 'name', 'id', 'value', 'type')
  13. $strippedData[$key] = array_values(array_filter($value, function ($item) {
  14. return !in_array($item, ['name', 'id', 'value', 'type']);
  15. }));
  16. }
  17. return $strippedData;
  18. }
  19. //Example usage (can be removed)
  20. /*
  21. $formData = [
  22. 'name' => ['name' => 'John Doe', 'id' => 123, 'value' => 'some value', 'type' => 'text'],
  23. 'email' => ['name' => 'Email', 'value' => 'john.doe@example.com'],
  24. 'address' => ['name' => 'Address', 'value' => ['street' => '123 Main St', 'city' => 'Anytown']],
  25. ];
  26. $stripped = stripMetadata($formData);
  27. print_r($stripped);
  28. */
  29. ?>

Add your comment