<?php
/**
* Teardown function for debugging date values with default values.
*
* @param array $data An array of data containing dates.
* @param array $defaults An array of default date values.
* @return array The modified data with default dates.
*/
function teardownDates(array $data, array $defaults): array
{
$newData = [];
foreach ($data as $key => $value) {
if (is_string($value) || is_int($value) || is_float($value)) { // Check if it's a potential date
if (isset($defaults[$key])) {
$newData[$key] = $defaults[$key]; // Use default if available
} else {
$newData[$key] = null; // Use null if no default is found
}
} else {
$newData[$key] = $value; // Keep non-date values as is
}
}
return $newData;
}
// Example usage (can be removed for just the function)
/*
$data = [
'date1' => '2023-10-26',
'date2' => 1698417600,
'date3' => 'invalid date',
'other' => 'some value'
];
$defaults = [
'date1' => '2023-01-01',
'date2' => 0,
'date4' => '2024-01-01'
];
$teardownData = teardownDates($data, $defaults);
print_r($teardownData);
*/
?>
Add your comment