<?php
/**
* Attaches timestamp metadata to a batch of data.
*
* @param array $data An array of data items (e.g., files, records).
* @param string $timestampKey The key to store the timestamp metadata.
* @return array The modified data array with timestamp metadata added.
*/
function attachTimestamps(array $data, string $timestampKey = 'timestamp')
{
// Get the current timestamp.
$timestamp = time();
// Iterate over the data and add the timestamp metadata.
foreach ($data as &$item) { // Use & to modify the original array
$item[$timestampKey] = $timestamp; // Add the timestamp to each item
}
return $data;
}
/**
* Example usage:
*/
// Sample data (replace with your actual data).
$batchData = [
['name' => 'File 1', 'content' => 'Some content'],
['name' => 'File 2', 'content' => 'More content'],
['name' => 'File 3', 'content' => 'Even more content'],
];
// Attach the timestamp metadata.
$timestampedData = attachTimestamps($batchData);
// Output the timestamped data (for demonstration).
print_r($timestampedData);
?>
Add your comment