- strftime: documentation ( source)
- strtotime: documentation ( source)
- setlocale: documentation ( source)
<?php
/**
* Returns the day name according to the current locale
*
* @param int $n The day number (ISO-8601 numeric representation)
* @param string $lc The desired locale for the returned day name
*
* @return string The day name
*/
function day_name(int $n, string $lc = "en_GB")
{
// Store the current locale so that we can reset it
$olc = setlocale(LC_TIME, "0");
// Set the locale according to the $locale passed in
setlocale(LC_TIME, $lc);
// Get the day name according to the $locale passed in
$output = strftime("%A", strtotime("Last Sunday +{$n} days"));
// Reset the locale
setLocale(LC_TIME, $olc);
// Return the day name
return $output;
}
echo day_name(4, "fr_FR");